dealloc Don't Use Accessor Methods in Init and Dealloc

来源:互联网 发布:淘宝短信链接 编辑:程序博客网 时间:2024/05/01 14:06

http://fann.im/blog/2012/08/14/dont-use-accessor-methods-in-init-and-dealloc/

http://stackoverflow.com/questions/8056188/should-i-refer-to-self-property-in-the-init-method-with-arc/8056260#8056260


http://stackoverflow.com/questions/5932677/initializing-a-property-dot-notation/5932733#5932733


Use direct access in partially constructed states, regardless of ARC:

- (id)initWithReminder:(Reminder*)reminder_ {    self = [super init];    if (self) {        reminder = reminder_;        // OR        reminder = [reminder_ retain];    }    return self;}

This is because self.whatever will trigger other side effects, such as Key-Value Coding notifications or maybe others (if your class or a subclass overrides setWhatever:), and that could expose other code to your partially-initialized object.

Some more detail as to why you should use direct access in partially constructed states (ARC || MRC) can be found here.


原创粉丝点击