using ARC, lifetime qualifier assign and unsafe_unretained

戏子无情 提交于 2019-11-27 06:12:20

问题


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.

  • Can I exchange unsafe_unretained with assign ?
  • Are these qualifiers the same thing ?

It would be really interesting any link of Apple documentation on this argument... I can find only a few rows here


回答1:


Clang's technical specification of ARC goes into much more detail about how the qualifiers work.

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.

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.)



来源:https://stackoverflow.com/questions/8397511/using-arc-lifetime-qualifier-assign-and-unsafe-unretained

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!