unsafe_unretain和弱,并在ARC下分配? [英] unsafe_unretained and weak and assign under ARC?
问题描述
Possible Duplicate:
strong / weak / retain / unsafe_unretained / assign
在ARC下,unsafe_unretained和弱和分配之间有什么区别? 非常感谢.
what's difference between unsafe_unretained and weak and assign under ARC? thanks a lot.
推荐答案
来自文档:
弱指定一个引用,该引用不能使引用的对象保持活动状态.如果没有强引用,则将弱引用设置为nil 对对象的引用.
weak specifies a reference that does not keep the referenced object alive. A weak reference is set to nil when there are no strong references to the object.
Assign
与weak
相同,除了它不会将释放实例的指针设置为nil,从而可能留下悬空的指针. Assign
和unsafe_unretained
的用法相同.
Assign
is identical to weak
except that it does not set pointers to deallocated instances to nil, potentially leaving dangling pointers. Assign
and unsafe_unretained
are identical in usage.
噢,我的天,看来我对属性属性和所有权限定词大为困惑;我最初的答案是正确的. Assign
和unsafe_unretained
都是属性属性,它们暗示其后备实例变量的所有权限定符__unsafe_unretained
.使用unsafe_unretained
与iOS 4向后兼容,否则使用assign
.
Oh my, it seems I massively confused property attributes and ownership qualifiers; my original answer was the correct one. Assign
and unsafe_unretained
are both property attributes that imply the ownership qualifier __unsafe_unretained
for their backing instance variables. Use unsafe_unretained
for backwards compatibility with iOS 4 and assign
otherwise.
这篇关于unsafe_unretain和弱,并在ARC下分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!