我知道在类的方法中分配值的正确约定是不使用 setter 版本。
鉴于您有这样的 init 方法:
// Class header
@property (nonatomic, weak) id <DelegateType> delegate;
@property (nonatomic, strong) NSString *stringData;
@synthesize delegate = _delegate;
@synthesize stringData = _stringData;
- (id)initWithParams:(NSString *)aString delegate:(id<DelegateType>)aDelegate
{
// initialization happens here
}
在 ARC 之前,您将通过以下方式确保正确的保留政策:
stringData = [aString retain];
self.delegate = aDelegate;
使用 ARC,如何完成作业并确保不会过早发布 ivars?
因为你不知道在 setter 覆盖的情况下可能在幕后发生什么样的工作,所以我的印象是你不能做:
self.stringData = aString
什么是正确的初始化模式?