使用ARC,生命周期限定符分配和unsafe_unretained [英] using ARC, lifetime qualifier assign and unsafe_unretained
问题描述
我对这两个限定符有点困惑...
使用ARC而不是使用弱
(即如果我需要支持iOS 4)我可以使用 unsafe_unretained
丢失auto-nil功能......最终结果似乎类似于 assign
。
i'm a little confused about these two qualifiers...
With ARC instead of using weak
(i.e. if I need support iOS 4) I can use unsafe_unretained
losing the auto-nil features... the final result seems to be similar to assign
.
- 我可以用
分配
unsafe_unretained >? - 这些限定符是否相同?
- Can I exchange
unsafe_unretained
withassign
? - Are these qualifiers the same thing ?
关于这个论点的Apple文档的任何链接都会非常有趣......我只能找到几行这里
It would be really interesting any link of Apple documentation on this argument... I can find only a few rows here
推荐答案
Clang的 ARC的技术规范详细介绍了限定符的工作原理。
Clang's technical specification of ARC goes into much more detail about how the qualifiers work.
但是,要回答你的问题: assign
和 __ unsafe_unretained
不是一回事。 assign
是一个属性属性,它告诉编译器如何合成属性的setter实现,而 __ unsafe_unretained
是一个所有权限定符,告诉ARC如何插入 retain
/ release
调用。但它们是相关的:在声明属性时, assign
暗示 __ unsafe_unretained
所有权。
But, to answer your question: assign
and __unsafe_unretained
are not the same thing. assign
is a property attribute that tells the compiler how to synthesise the property's setter implementation, while __unsafe_unretained
is an ownership qualifier that tells ARC how to insert retain
/release
calls. But they are related: when declaring a property, assign
implies __unsafe_unretained
ownership.
在ARC之前, assign
是默认的属性所有权限定符;但启用ARC后,可保留对象指针类型的默认值为 strong
。 (对于标量和其他指针类型, assign
仍然是默认值。)
Prior to ARC, assign
was the default property ownership qualifier; but with ARC enabled, the default for retainable object pointer types is strong
. (For scalars and other pointer types, assign
is still the default.)
这篇关于使用ARC,生命周期限定符分配和unsafe_unretained的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!