objective C underscore property vs self

前端 未结 4 1434
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 00:28

I\'m was playing around with the standard sample split view that gets created when you select a split view application in Xcode, and after adding a few fields i needed to ad

4条回答
  •  醉酒成梦
    2021-01-04 01:05

    I'll make an example (without ARC enabled):

    @property (nonatomic, retain) NSNumber* number;
    

    If you don't synthesize it, you can access it this way:

    self.number= [NSNumber numberWithBool: YES];
    

    This case the number is retained.If instead you synthesize it and don't use the property:

    @synthesize number;
    

    Later in the file:

    number=[NSNUmber numberWithBool: YES];
    

    You haven't used the property, so the number is not retained.That makes a relevant difference between using accessors and synthesized properties.

提交回复
热议问题