iphone – iOS 5中的协议和分配属性

前端之家收集整理的这篇文章主要介绍了iphone – iOS 5中的协议和分配属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在iOS 5中创建自己的自定义代理.
在iOS 4中,我通常使用’Assign’属性

@property(nonatomic,assign) id<AnyProtocol> delegate;

现在,当我尝试合成时,我收到以下错误消息:

error: Automatic Reference Counting Issue: Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be __unsafe_unretained

有任何想法吗 ?

解决方法

错误是因为在ARC ivars下默认为strong

错误告诉您已使用__unsafe_unretained(assign)所有权声明了属性,但默认情况下,ivar具有__strong所有权,因此它们不能在一个中.您可以

>省略将自动创建的ivar
>定义ivar以匹配您的(assign)属性声明:

__unsafe_unretained id <FileListDelegate> delegate;

>定义属性以匹配ivar的隐式__strong所有权:

@property (weak) id <FileListDelegate> delegate;

这三个选项无耻地从用户chrispix的答案中复制了this thread..Credit去了那里

猜你在找的Xcode相关文章