OC property 屬性設(shè)置解釋
This link has the break down
http://clang.llvm.org/docs/AutomaticReferenceCounting.html#ownership.spelling.property
assign implies __unsafe_unretained ownership.
copy implies __strong ownership, as well as the usual behavior of copy
semantics on the setter.retain implies __strong ownership.
strong implies __strong ownership.
unsafe_unretained implies __unsafe_unretained ownership.
weak implies __weak ownership.
具體可參考獅子書 XD
一般實(shí)踐:
delegate -> weak
IBOutLet -> weak
int, BOOL -> assign
copy 有點(diǎn)特殊,主要針對NSString
1.定義NSString的指針,當(dāng)源字符串是NSString時(shí),不管是copy還是string都是淺拷貝。
2.定義NSString的指針,當(dāng)源字符串是NSMutableString時(shí),strong是淺拷貝,而copy是深拷貝。這樣,當(dāng)有人從NSMutableString那邊修改時(shí),用了copy的NSString因?yàn)槭巧羁截?,就不會被影響,而strong的話就會發(fā)現(xiàn)明明是NSString卻被改變了,所以建議使用copy。