error: synthesized property 'name' must either be named the same as a compatible instance variable o

#import <Foundation/Foundation.h>

@interface Person : NSObject{
    NSString * _name;
    NSUInteger _age;
}

@property (nonatomic, copy) NSString* name;
@property (nonatomic, assign) NSUInteger age;

@end
@implementation Person

@synthesize name = _name;
@synthesize age = _age;

@end

正確實現如上述代碼,以前參照Object-C程序設計 (第4版)寫的實例,就是報:atom

error: synthesized property 'name' must either be named the same as a compatible instance variable or must explicitly name an  instance variable錯誤。spa

參考書中改代碼以下:設計

#import <Foundation/Foundation.h>

@interface Person : NSObject

@property (nonatomic, copy) NSString* name;
@property (nonatomic, assign) NSUInteger age;

@end
相關文章
相關標籤/搜索