понедельник, 18 февраля 2019 г.

про ARC

Перечитывал доку по ARC, захотелось зафиксировать

  • You cannot give an accessor a name that begins with new.
    ошибка -- @property NSString *newTitle;
    норм -- @property NSString *newtitle;
  • You cannot use memory zones.
    NSZone -- старая фишка для работы с памятью,  присутствует в интерфейсе но не используется
Еще прикольная тема


NSError *error;
BOOL OK = [myObject performOperationWithError:&error];
if (!OK) {
    // Report the error.
    // ...
However, the error declaration is implicitly:
NSError * __strong e;
and the method declaration would typically be:
-(BOOL)performOperationWithError:(NSError * __autoreleasing *)error;
The compiler therefore rewrites the code:
NSError * __strong error;
NSError * __autoreleasing tmp = error;
BOOL OK = [myObject performOperationWithError:&tmp];
error = tmp;
if (!OK) {
    // Report the error.
    // ...
The mismatch between the local variable declaration (__strong) and the parameter (__autoreleasing) causes the compiler to create the temporary variable. You can get the original pointer by declaring the parameter id __strong * when you take the address of a __strong variable. Alternatively you can declare the variable as __autoreleasing.

Комментариев нет:

Отправить комментарий