Apple recommend "Do not Use Accessor Methods in Initializer Methods and dealloc" with this document: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html
If I want to set up the block in the initializer methods, block references to the property, how I write better code?
typedef void(^customBlock)();
@interface CustomObject : NSObject
@property (nonatomic, strong) NSString *string;
@property (nonatomic, copy) customBlock customBlock1;
@property (nonatomic, copy) customBlock customBlock2;
@end
@implementation CustomObject
- (instancetype)init {
self = [super init];
if (self) {
__weak __typeof(self) weakSelf = self;
_customBlock1 = ^ {
__typeof(self) strongSelf = weakSelf;
strongSelf -> _string = @"string by iVar";
};
_customBlock2 = ^{
weakSelf.string = @"string by accessor";
};
}
return self;
}
@end