【发布时间】:2015-02-05 13:57:05
【问题描述】:
这是我的情况,我声明一个objective-c类如下:
@interface FileItem : NSObject
@property (nonatomic, strong, readonly) NSString *path;
@property (nonatomic, strong, readonly) NSArray* childItems;
- (id)initWithPath:(NSString*)path;
@end
@implementation LCDFileItem
- (id)initWithPath:(NSString*)path {
self = [super init];
if (self) {
_path = path;
}
return self;
}
- (NSArray*)childItems {
if (!_childItems) { // error, _childItems undeclared!
NSError *error;
NSMutableArray *items = [[NSMutableArray alloc] init];
_childItems = items; // error, _childItems undeclared!
}
return _childItems; // error, _childItems undeclared!
}
我将“path”和“childItems”标记为只读属性,编译器抱怨“_childItems”标识符未声明,似乎我不能使用“-(NSArray*)childItem”作为“childItem”属性' s getter 函数(我改了函数名,一切正常),为什么? 我理解“只读”属性使 xcode 省略了属性的 setter 函数,但是对 getter 函数有什么影响?
【问题讨论】:
标签: objective-c xcode properties