记奇特的调试bug

奇特的调试bug.png

传进来的model有值,并且可以打印model模型所有值;
但是打印model模型中的titleimagesort属性的时候,不是为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为一个字典

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
id = ad3886be78de49c8a6f66dfe9ba715fa,
enable = 0,
album = 1,
delFlag = 1,
ifBuy = 0,
createDate = 1505893668000,
vtime = ,
type = 0,
title = 微课堂,
price = 1,
image = 65617e87de1c4084ba1b78a673363b99,
updateDate = 1508724726000,
sort = 1
}

正确的打印出来如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
(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类型数据没有转换为模型类型!!!

查看模型中的声明和实现如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
.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<NSString *, id> *)modelCustomPropertyMapper {
return @{@"videoId":@"id"};
}
@end
@implementation videosListModel
@end

在.m文件中缺少了YYModel的类方法(自定义容器类属性映射模型类的方法)

1
2
3
+ (NSDictionary *)modelContainerPropertyGenericClass {
return @{@"videos" : [videosModel class]};
}