1、模型中包含数组模型,在.m文件中加入modelContainerPropertyGenericClass方法
@interface XMallSpecificationModel : NSObject <YYModel>
@property (nonatomic, copy) NSString *carSpecificationName;
@property (nonatomic, copy) NSString *iconPicFileUrl;
@end
@interface XMallOrderModel : NSObject <YYModel>
@property (nonatomic, copy) NSString *orderCode;
@property (nonatomic, copy) NSArray<XMallSpecificationModel*> *optionalSpecificationList;
@end
//.m文件
+ (NSDictionary *)modelContainerPropertyGenericClass {
return @{@"optionalSpecificationList":[XMallSpecificationModel class]};
}
2、修改模型中的值
- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic{
unsigned int outCount = 0;
Ivar *ivars = class_copyIvarList([self class], &outCount);
for (int i = 0; i < outCount; i++) {
Ivar ivar = ivars[i];
NSString *key = [NSString stringWithUTF8String:ivar_getName(ivar)];
NSString *type = [NSString stringWithUTF8String:ivar_getTypeEncoding(ivar)];
id value = [self valueForKeyPath:key];
if ([type containsString:@"NSString"]&&[self isEmptyStr:value]) {
[self setValue:@"" forKey:key];
}
}
// 释放内存!
free(ivars);
return YES;
}
4、归档与解挡
- (void)encodeWithCoder:(NSCoder *)aCoder {
[self yy_modelEncodeWithCoder:aCoder];
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super init];
return [self yy_modelInitWithCoder:aDecoder];
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)