error: synthesized property 'name' must either be named the same as a compatible instance variable or must explicitly name an instance variable问题解决

#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版)写的实例,就是报:

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

参考书中改代码如下:

#import <Foundation/Foundation.h>

@interface Person : NSObject

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

@end
原文地址:https://www.cnblogs.com/yanwei-wang/p/8676100.html