强弱财产有什么区别? [英] what is the difference between strong and weak property?

查看:158
本文介绍了强弱财产有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 5中的强弱属性是新的。
如果有人告诉我何时使用了哪个属性。

As strong and weak properties are new in iOS 5. If any one tell me which property is used when.

当我们应该使用强或者什么时候我们应该使用弱?

When we should use strong or when we should use weak?

@property(nonatomic,strong)

@property(nonatomic,weak)


推荐答案

表示只要此属性指向一个对象,该对象就不会自动释放。在非ARC中,它是 retain 的同义词。

Strong means that as long as this property points to an object, that object will not be automatically released. In non-ARC it's a synonym for retain.

相反,意味着属性指向的对象可以自由释放,但前提是它将属性设置为 nil 。在ARC中,您使用weak来确保您不拥有它指向的对象。

Weak instead, means that the object the property points to, is free to release but only if it sets the property to nil. In ARC you use weak to ensure you do not own the object it points to.

这篇关于强弱财产有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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