iOS中@property的默认值是什么? [英] What are the defaults values for @property in iOS?

查看:129
本文介绍了iOS中@property的默认值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS中@property的默认值是什么?

例如,如果我声明@property NSString * Photographer;

是默认值(assign)还是(retain)还是其他值?

(原子的,非原子的)?

我无法从文档中找到此信息.谢谢

解决方案

我相信默认值为(原子,分配),但是,您不应将其保留为空.

默认值可能随时更改,并且您正在编写依赖于属性定义的代码.

例如,如果您依赖默认的 assign ,并且以后出于任何原因将其更改为 retain ,那么您的所有代码都将泄漏./p>

相反,如果默认值是keep,并且您依靠它保留并且更改为assign,那么当您不可避免地过度释放对象时,您的代码将崩溃.

不要依赖任何默认值,无论它们是什么.

明确定义属性的属性.

What are the defaults values for @property in iOS ?

For example, if I declare @property NSString* photographer;

is the default value (assign) or (retain) or what else ?

(atomic, non-atomic) ?

I cannot find this information from the documentation. thanks

解决方案

I believe the defaults are (atomic, assign), however, you should not leave them empty.

The default may change at any point, and you're writing code that is relying on the definition of the property.

For example, if you rely on the default assign and it changes to retain for whatever reason in the future, then all of your code is going to leak.

Conversely, if the default is retain and you rely on that and it changes to assign, then your code is going to crash when you inevitably over release an object.

Do not rely on any default, regardless of what they may be.

Explicitly define your properties' attributes.

这篇关于iOS中@property的默认值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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