当我定义一个继承自NSObject
的新类时:
@interface Photo : NSObject
{
NSString* caption;
NSString* photographer;
}
@property NSString* caption;
@property NSString* photographer;
@end
是新类alloc
继承的NSObject
中的所有类方法(如Photo
)?
答案 0 :(得分:5)
是的,Photo
可以在您NSObject
的子类时使用NSObject
的任何方法/属性/ ivar / etc(除了声明为@private
的iVars除外):
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]);
有关@private
的更多信息 - > SO Question: what-does-private-mean-in-objective-c