处理Model : 推荐采用适配器模式
目标接口
@protocol BusinessCardAdapterProtocol <NSObject>
- (NSString *)name;
- (UIColor *)lineColor;
- (NSString *)phoneNumber;
@end
//目标对象
/**
* 名字
*/
@property (nonatomic, strong) NSString *name;
/**
* 线条颜色
*/
@property (nonatomic, strong) UIColor *lineColor;
/**
* 电话号码
*/
@property (nonatomic, strong) NSString *phoneNumber;
//输入方使用适配器
BusinessCardAdapter *modelAdapter = [[CardAdapter alloc] initWithData:model]2;
//适配器初始化函数
- (instancetype)initWithData:(id)data {
self = [super init];
if (self) {
self.data = data;
}
return self;
}
使用方使用适配器
- (void)loadData:(id <BusinessCardAdapterProtocol>)data {
self.name = [data name];
self.lineColor = [data lineColor];
self.phoneNumber = [data phoneNumber];
}
网友评论