问题描述
我注意到Apple的一些示例在属性上同时包含了retain
和readonly
修饰符.如果在使用readonly
修饰符时没有生成设置器,那么包含retain
有什么意义?
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?
示例:AnimatedTableView示例中的@property (retain, readonly) NSString *title;
.
Example: @property (retain, readonly) NSString *title;
from the AnimatedTableView sample.
推荐答案
您可以在类扩展中包含第二个私有读写声明.所有引用的内存管理方案都需要匹配IIRC,因此您会像只读,保留"这样愚蠢.
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".
这篇关于为什么声明的属性同时使用保留和只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!