Automatic iVars with @synthesize

后端 未结 3 1786
再見小時候
再見小時候 2021-01-01 01:48

I understand that starting with iOS 4, there is now the ability to not declare iVars at all, and allow the compiler to automatically create them for you when you synthesize

3条回答
  •  爱一瞬间的悲伤
    2021-01-01 02:15

    In constrast, I do the following:

    @interface SomeViewController : UIViewController
    
    @property (nonatomic, copy) NSString *someString;
    
    @end
    

    and then

    @implementation SomeViewController
    
    @synthesize someString;
    
    - (void)dealloc
    {
        [someString release], someString = nil;
        self.someString = nil; // Needed?
    
        [super dealloc];
    }
    
    @end
    

    Note: At some point Apple will enable synthesize-by-default which will no longer require the @synthesize directive.

提交回复
热议问题