传进来的model有值,并且可以打印model模型所有值;
但是打印model模型中的title
、image
、sort
属性的时候,不是为nil,就是报错如下:
Execution was interrupted, reason: Attempted to dereference an invalid ObjC Object or send it an unrecognized selector. The process has been returned to the state before expression evaluation
原因排查:
打印的model
为一个字典
{
id = ad3886be78de49c8a6f66dfe9ba715fa,
enable = 0,
album = 1,
delFlag = 1,
ifBuy = 0,
createDate = 1505893668000,
vtime = ,
type = 0,
title = 微课堂,
price = 1,
image = 65617e87de1c4084ba1b78a673363b99,
updateDate = 1508724726000,
sort = 1
}
正确的打印出来如下:
(lldb) po model.yy_modelDescription
< videosModel: 0x600002a75700> {
enable = "0";
ifBuy = 0;
image = "b31e4d4ac6fd472babe9bae7c768bc0d";
price = 2;
title = "政策解读1";
type = "1";
videoId = "4bb5310dcb9d4e7cb20aa00796da921f"
}
(lldb) po model
< videosModel: 0x600002a75700>
排查得出结果:网络请求回来的json类型数据没有转换为模型类型!!!
查看模型中的声明和实现如下
.h
@interface videosModel : NSObject
@property (nonatomic, copy) NSString *videoId;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *type;
@property (nonatomic, copy) NSString *enable;
@property (nonatomic, copy) NSString *image;
@property (nonatomic, assign) NSInteger ifBuy;
@property (nonatomic, strong) NSNumber *price;
@end
@interface videosListModel : NSObject
@property (nonatomic, strong) NSArray < videosModel *> *videos;
@end
.m
@implementation videosModel
+ (nullable NSDictionary *)modelCustomPropertyMapper {
return @{@"videoId":@"id"};
}
@end
@implementation videosListModel
@end
在.m文件中缺少了YYModel的类方法(自定义容器类属性映射模型类的方法)
+ (NSDictionary *)modelContainerPropertyGenericClass {
return @{@"videos" : [videosModel class]};
}