Extension 延展 也是扩充类的一种方式, 只不过延展的扩充是私有的, 是在.m文件中定义的 延展既可以扩展方法也可以扩展实例变量, 只不过都是私有的, 外界无法直接访问, 延展是为有源代码的类扩充内容
@interface Person () {
NSString *_aa;
NSString *_bb;//延展中添加私有实例变量
}
- (void)sayMorning;
- (void)sayAfternoon;
- (void)sayEvening;
@end<pre name="code" class="objc">@implementation Person
- (void)sayHi {
_aa = @"vaercly";
_bb = @"Frank";
NSLog(@"%@ and %@", _aa, _bb);
[self sayMorning];
[self sayAfternoon];
[self sayEvening];
}
//早上好
- (void)sayMorning {
NSLog(@"good, morning");
}
//中午好
- (void)sayAfternoon {
NSLog(@"good, afternoon");
}
//晚上好
- (void)sayEvening {
NSLog(@"good, evening");
}
@end