小编tok*_*kou的帖子

当我提供getter和setter时,为什么需要编写@synthesize?

因此自动合成属性非常棒.但是,当您同时提供getter和setter时,会出现错误.

@property (strong, nonatomic) NSArray *testArray;

- (NSArray *)testArray {
    return _testArray;
}

- (void)setTestArray:(NSArray *)testArray {
    _testArray = testArray;
}
Run Code Online (Sandbox Code Playgroud)

错误:Use of undeclared identifier '_testArray'.

添加@synthesize testArray = _testArray;解决了问题.我只是想知道为什么会这样?

properties objective-c synthesize

8
推荐指数
2
解决办法
4277
查看次数

标签 统计

objective-c ×1

properties ×1

synthesize ×1