gpt4 book ai didi

iphone - 强IBOutlets和弱IBOutlets的区别

转载 作者:可可西里 更新时间:2023-11-01 03:27:28 27 4
gpt4 key购买 nike

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

我之前使用的是 4.3 SDK,其中不存在强大的 IBOutlets。此外,(自动)发布在 iOS 5.1 SDK 中不可用。

最佳答案

Strong 表示只要这个属性指向一个对象,那个对象就不会自动释放。在非 ARC 中,它是 retain

的同义词

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

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

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。

也看看here, at Apple's documents .

从那里开始,例子是

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

同时检查 this了解更多关于 strongweak 的信息。

关于iphone - 强IBOutlets和弱IBOutlets的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11168992/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com