In Objective-C with ARC, is it true that we usually only need to specify nonatomic as property attributes?

后端 未结 2 1428
天命终不由人
天命终不由人 2020-12-30 11:12

It is strange that in Big Nerd Ranch iOS 5 book (p.73) and Programming iOS 5 book (O\'Reilly, p.314) (updadte: even Kochan\'s Objective-C book Fourth edition)

相关标签:
2条回答
  • 2020-12-30 11:45

    readwrite and strong, are indeed the default under ARC*. Under manual reference counting, assign was (is) the default. I prefer to explicitly specify these, because it makes it clearer what the @property's parameters are instead of relying on the person reading the code knowing what the defaults are.

    *strong is the default assuming you've either let the compiler synthesize an instance variable for you, or have declared an instance variable without an explicit ownership qualifier (in which case the ivar is __strong by default anyway). Otherwise, the default property ownership type matches the ownership qualifier in the ivar's declaration. So, if you explicitly declare an ivar with __weak, then declare an @property for it without an ownership qualifier, the synthesized property will be weak. This is all documented in the Clang ARC documentation.

    0 讨论(0)
  • 2020-12-30 12:04

    By default, an object property is strong, atomic, readwrite. See https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html

    0 讨论(0)
提交回复
热议问题