ios 协议(delegate)使用过程中遇到assign attribute must be unsafeunretained

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012490014/article/details/44751147

今天在使用协议的过程中,偶然发现这样使用

@interface AppDelegate (){
    id<ChatDelegate>  testdelegate;
}
@property (nonatomic , assign) id<ChatDelegate> testdelegate;

@end

@implementation AppDelegate
@synthesize testdelegate;

会报错:

Existing instance variable 'delegate' for property 'delegate' with assign attribute must be unsafe unretained

修改成:


@interface AppDelegate (){
   __unsafe_unretained id<ChatDelegate>  testdelegate;
}
@property (nonatomic , assign) id<ChatDelegate> testdelegate;

@end

@implementation AppDelegate
@synthesize testdelegate;

就好了,这只是为了相容iOS4以下的版本

参考:http://www.cnblogs.com/lyanet/archive/2013/05/07/3064290.html


猜你喜欢

转载自blog.csdn.net/u012490014/article/details/44751147