一般來說, 在 objective C 宣告和實作應該會分別存放在 .h 和 .m 檔中,
然後用 @interface ... @end 和 @implementation ...@end 標開來,
但是有時候 @interface 也會出現在 .m 中 , 像這樣
Person.h:
@interface Person
{
NSString *_name;
}
@property(readwrite, copy) NSString *name;
-(NSString*)makeSmallTalkWith:(Person*)person;
@end
Person.m:
@interface Person () //Not specifying a name for the category makes compiler checks that these methods are implemented.
-(void)startThinkOfWhatToHaveForDinner;
@end
@implementation Person
@synthesize name = _name;
-(NSString*)makeSmallTalkWith:(Person*)person
{
[self startThinkOfWhatToHaveForDinner];
return @"How's your day?";
}
-(void)startThinkOfWhatToHaveForDinner
{
}
@end
文中的解釋是說. 在 .m 檔的 @interface 中的宣告叫做 "class extension"(類別延伸?), 自動會變成 private ,
more info : http://macdevelopertips.com/objective-c/objective-c-categories.html
沒有留言:
張貼留言