error:assign attribute must be unsafeunretained

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

 

?

1
2
3
4
5
6
7
8
9
10
@interface AppDelegate (){
    id<chatdelegate>  testdelegate;
}
@property (nonatomic , assign) id<chatdelegate> testdelegate;
 
@end
 
@implementation AppDelegate
@synthesize testdelegate;
</chatdelegate></chatdelegate>

会报错:

 

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

改动成:

 

?
1
2
3
4
5
6
7
8
9
10
@interface AppDelegate (){
   __unsafe_unretained id<chatdelegate>  testdelegate;
}
@property (nonatomic , assign) id<chatdelegate> testdelegate;
 
@end
 
@implementation AppDelegate
@synthesize testdelegate;
</chatdelegate></chatdelegate>

就好了,这仅仅是为了相容iOS4下面的版本号

 


原文地址:https://www.cnblogs.com/gccbuaa/p/6941578.html