为什么声明的属性同时使用保留和只读? [英] Why does a declared property use both retain and readonly?

查看:66
本文介绍了为什么声明的属性同时使用保留和只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到Apple的一些示例在属性上同时包含了retainreadonly修饰符.如果在使用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".

这篇关于为什么声明的属性同时使用保留和只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆