当我定义一个继承自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