Ho letto un numero di snippet che menzionano che non si dovrebbe mai usare la notazione a punti nei metodi init o dealloc. Tuttavia, non riesco mai a capire perché. Un post ha fatto cenno che ha a che fare con KVO, ma non di più.Objective-C Dot Syntax e Init
@interface MyClass : NSObject {
SomeObject *object_;
}
@property (nonatomic, retain) SomeObject *object;
@end
Questa implementazione è negativa?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
self.object = object;
}
return self;
}
@end
Ma questo va bene?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
object_ = [object retain];
}
return self;
}
@end
Quali sono le insidie nell'utilizzo di dot-notation all'interno di init?
Sembra nel 2 ° esempio che dovresti scrivere object_ = [object retain]; – Vladimir
risolto, il problema con esempi scritti rapidamente. ;) – MarkPowell