当我定义一个继承自NSObject的新类时:

@interface Photo : NSObject
{
    NSString* caption;
    NSString* photographer;
}

@property NSString* caption;
@property NSString* photographer;

@end

alloc中的所有类方法(如NSObject)是否都由新类继承?

最佳答案

是的,可以使用任何方法/属性/IVAR/ETC(除了那些IVARS声明的Photo),当你的子类@private

Photo *myPhoto;
myPhoto = [[Photo alloc] init];
// ... Do some myPhoto stuff ...
NSLog(@"Photo object: %@", myPhoto);
NSLog(@"Photo description: %@", [myPhoto description]);
NSLog(@"Photo caption: %@", [myPhoto caption]);
NSLog(@"Photo photographer: %@", [myPhoto photographer]);

关于NSObject>NSObject的更多信息
SO Question: what-does-private-mean-in-objective-c

07-26 09:43