YYModel icon indicating copy to clipboard operation
YYModel copied to clipboard

将对象添加到数组,字典的一个bug

Open lanjing99 opened this issue 7 years ago • 1 comments

NSObject+YYModel.m line 951-953

NSObject *newOne = [cls new]; [newOne yy_modelSetWithDictionary:(id)oneValue]; if (newOne) dic[oneKey] = newOne;

这里的newOne是不会为nil的,所以就算yy_modelSetWithDictionary返回false,创建对象失败,也会被添加到数组里。类似的还有添加到数据和set的判断。我在代码中是这样改的,之前提过一个合并的request,不知道为什么没通过: NSObject *newOne = [cls new]; if( [newOne yy_modelSetWithDictionary:(id)oneValue]){ dic[oneKey] = newOne; }

lanjing99 avatar Aug 25 '17 10:08 lanjing99

NSObject+YYModel.m line 1019-1030

                if (one) {
                    [one yy_modelSetWithDictionary:value];
                } else {
                    Class cls = meta->_cls;
                    if (meta->_hasCustomClassFromDictionary) {
                        cls = [cls modelCustomClassForDictionary:value];
                        if (!cls) cls = meta->_genericCls; // for xcode code coverage
                    }
                    one = [cls new];
                    [one yy_modelSetWithDictionary:value];
                    ((void (*)(id, SEL, id))(void *) objc_msgSend)((id)model, meta->_setter, (id)one);
                }

这里也是同样的问题,yy_modelSetWithDictionary:的返回NO的情况,有多处逻辑都没有对结果进行检查。

mistyzyq avatar Sep 21 '17 12:09 mistyzyq