强弱IBOutlets之间的区别 [英] Difference between Strong and Weak IBOutlets

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

问题描述

Xcode iOS 5.1 SDK中的 strong IBOutlets有什么区别?

What is the difference between strong and weak IBOutlets in the Xcode iOS 5.1 SDK?

我之前使用的是4.3 SDK,其中没有强大的IBOutlets。此外,iOS 5.1 SDK中不提供(自动)版本。

I was previously using the 4.3 SDK, where strong IBOutlets did not exist. In addition, (auto)release is not available in the iOS 5.1 SDK.

推荐答案

强大表示只要此属性指向一个对象,该对象就不会自动释放。在非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


指定强大(拥有)与
目标对象的关系。

Specifies that there is a strong (owning) relationship to the destination object.

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

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


指定存在弱(非拥有)关系到
目标对象。如果目标对象已取消分配,则
属性值将自动设置为nil。

Specifies that there is a weak (non-owning) relationship to the destination object. If the destination object is deallocated, the property value is automatically set to nil.

Nonatomic 表示如果多个线程尝试一次读取或更改属性,则可能发生错误。后果是会有部分写入的值或过度释放的对象= CRASH。

Nonatomic means that if multiple threads try to read or to change the property at once, badness can happen. Consequences are that there will be partially-written values or over-released objects = CRASH.

看看此处,Apple的文档

从那里,例子是

@property (weak) IBOutlet MyView *viewContainerSubview;
@property (strong) IBOutlet MyOtherClass *topLevelObject;

同时检查这个了解更多关于 strong 弱的信息

Check also this to know more about strong and weak.

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

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