I have read a number of snippets that mention you should never use dot-notation within your init or dealloc methods. However, I can never seem to find out why. One post did mention in passing that it has to do with KVO, but no more.
@interface MyClass : NSObject {
SomeObject *object_;
}
@property (nonatomic, retain) SomeObject *object;
@end
This implementation is bad?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
self.object = object;
}
return self;
}
@end
But this is good?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
object_ = [object retain];
}
return self;
}
@end
What are the pitfalls of using dot-notation inside your init?