I've noticed that some of Apple's examples include both a retain and readonly modifier on properties. What's the point of including retain if no setter gets generated when we're using the readonly modifier?
Example: @property (retain, readonly) NSString *title; from the AnimatedTableView sample.
|
23
12
|
I've noticed that some of Apple's examples include both a Example: | |||
|
add a comment
|
|
17
|
You can include a second, private readwrite declaration in a class extension. The memory management scheme for all references needs to match IIRC, so you get silliness like "readonly, retain". | ||||||||
|
|
36
|
Or, more specifically, (readonly, retain) enables a pattern like this: Foo.h:
Foo.m:
The end result is a property that is publicly readonly while being readwrite within the implementation and for whom both setter and getter are synthesized automatically by the compiler. A warning could be generated in the case of no (readwrite, retain) override in the class extension -- something akin to |
本文探讨了Objective-C中在属性声明中同时使用retain和readonly的逻辑与用意,解释了这种组合在内存管理、属性访问控制及代码模式上的应用。

2495






