不能使用weak修饰进行声明的类

These classes include NSTextViewNSFont and NSColorSpace; for the full list, see Transitioning to ARC Release Notes.

但是如果你真的想在这些类中使用weak进行修饰,可以使用不安全的修饰符unsafe_unretained

如:用unsafe_unretained修饰属性

  

@property (unsafe_unretained) NSObject *unsafeProperty;

__unsafe_unretained修饰变量
NSObject * __unsafe_unretained unsafeReference;

注意:虽然unsafe引用和weak的引用相似,都不会跟随对象的生命周期一直存在,但是weak被释放的时候是转变成空值的,而unsafe确不是,它会变成一个空指针,依然存在内存中,当发送信息给这个空指针的时候就会发生死机。

原文地址:https://www.cnblogs.com/lelun/p/5632533.html