在category里访问属性为什么需要用self.property的方式而不能使用_property

ClassA.h
@interface ClassA : NSObject
@property (nonatomic, copy) NSString *databasePath;
@end

ClassA.m
@implementation ClassA
@end

ClassA+Category.h
@interface YRRService (Category)
@end

ClassA+Category.m
@implementation YRRService (Category)

- (instancetype)initWithDatabaseFilename:(NSString *)dbFilename {
    self = [super init];
    if (self) {
        self.databaseFilename = dbFilename;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [paths objectAtIndex:0];
        self.databasePath = [documentsDirectory stringByAppendingPathComponent:self.databaseFilename];
        
        [self copyDatabaseIntoDocumentsDirectory];
    }
    return self;
}
@end
查看回复

相关问答