init 또는 dealloc 메서드 내에서 점 표기법을 사용해서는 안되는 언급의 스 니펫을 읽었습니다. 그러나 나는 결코 그 이유를 알 수없는 것 같습니다. 한 게시물은 KVO와 관련이 있다고 언급했지만 더 이상은 아닙니다.Objective-C Dot 구문 및 초기화
@interface MyClass : NSObject {
SomeObject *object_;
}
@property (nonatomic, retain) SomeObject *object;
@end
이 구현은 좋지 않습니까?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
self.object = object;
}
return self;
}
@end
그러나 이것은 좋은 것입니까?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
object_ = [object retain];
}
return self;
}
@end
init 내부에 점 표기법을 사용했을 때의 함정은 무엇입니까?
두 번째 예에서 object_ = [object retain]; – Vladimir
고정, 신속하게 작성된 예제의 문제. ;) – MarkPowell