代码:
1.创建Person类
#import
@interface Person :NSObject
@property (nonatomic,copy)NSString * name;
@end
2.创建Person的类别
#import "Person.h"
// 添加额外两个属性
@interface Person (addProperty)
@property (nonatomic,assign)NSInteger age;
@property (nonatomic,copy)NSString * stu;
@end
3.Person类别.m的实现
#import "Person+addProperty.h"
#import
@implementation Person (addProperty)
staticchar nameKey = 'n';
staticchar stuKey = 's';
// 给age属性提供getter和setter方法
- (NSInteger)age{
}
- (void)setAge:(NSInteger)age {
}
// 给stu属性提供getter和setter方法
- (NSString*)stu{
}
- (void)setStu:(NSString *)stu{
}
@end
4.用一下吧
#import "ViewController.h"
#import "Person+addProperty.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
}