@chenbinghua
2015-09-12T10:34:32.000000Z
字数 1070
阅读 1374
iOS笔记
转载自小码哥笔记
@interface Person (NJ)
{
// 错误写法
// int _age;
}
- (void)eat;
@end
@interface Person (NJ)
// 只会生成getter/setter方法的声明, 不会生成实现和私有成员变量
@property (nonatomic, assign) int age;
@end
@interface Person : NSObject
{
int _no;
}
@end
@implementation Person (NJ)
- (void)say
{
NSLog(@"%s", __func__);
// 可以访问原有类中得成员变量
NSLog(@"no = %i", _no);
}
@end
@implementation Person
- (void)sleep
{
NSLog(@"%s", __func__);
}
@end
@implementation Person (NJ)
- (void)sleep
{
NSLog(@"%s", __func__);
}
@end
int main(int argc, const char * argv[]) {
Person *p = [[Person alloc] init];
[p sleep];
return 0;
}
输出结果:
-[Person(NJ) sleep]
@implementation Person
- (void)sleep
{
NSLog(@"%s", __func__);
}
@end
@implementation Person (NJ)
- (void)sleep
{
NSLog(@"%s", __func__);
}
@end
@implementation Person (MJ)
- (void)sleep
{
NSLog(@"%s", __func__);
}
@end
int main(int argc, const char * argv[]) {
Person *p = [[Person alloc] init];
[p sleep];
return 0;
}
输出结果:
-[Person(MJ) sleep]