unsafe_unretain和弱,并在ARC下分配? [英] unsafe_unretained and weak and assign under ARC?

查看:84
本文介绍了unsafe_unretain和弱,并在ARC下分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
强/弱/保留/unsafe_unretained/分配

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.

Assignweak相同,除了它不会将释放实例的指针设置为nil,从而可能留下悬空的指针. Assignunsafe_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.

噢,我的天,看来我对属性属性和所有权限定词大为困惑;我最初的答案是正确的. Assignunsafe_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屋!

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