Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

objective c - using ARC, lifetime qualifier assign and unsafe_unretained

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...