1. 程式人生 > >ios 協議(delegate)使用過程中遇到assign attribute must be unsafeunretained

ios 協議(delegate)使用過程中遇到assign attribute must be unsafeunretained

今天在使用協議的過程中,偶然發現這樣使用

@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