ibireme / YYModel

High performance model framework for iOS/OSX.
MIT License
4.34k stars 917 forks source link

+[NSArray yy_modelArrayWithClass:json:]: unrecognized selector sent to class 0x1b21c5950 #248

Open lixiaoyu opened 6 years ago

lixiaoyu commented 6 years ago

正常的解析一段json的数组,报这个错,以前一直这么用 我的返回数据以及调用是这样的 NSArray * datalist = [NSArray yy_modelArrayWithClass:[NewSearchResult class] json:result[@"list"]]; json

{ list = ( { IsPackage = 0; PlatNum = 1; objectId = 190944; objectName = "\U5c0f\U59d0\Uff1a\U4f60\U597d\Uff01\U6211\U60f3\U91c7\U8bbf\U4f60\U4e00\U4e0b\U2026\U2026"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 187806; objectName = "\U3010\U6b63\U80fd\U91cf\U6bb5\U5b50\U3011\U6ef4\U6c34\U4e4b\U6069 \U5b9a\U5f53\U6d8c\U6cc9\U76f8\U62a5\Uff01\U8bf7\U73cd\U60dc\U8eab\U8fb9\U5bf9\U4f60\U597d\U7684\U4eba\Uff01#\U60c5\U611f\U89c6\U9891#"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 182070; objectName = "\U4e3a\U4e86\U4f60\U597d\Uff0c\U6700\U540e\U4e00\U6b21\U4e86\Uff0c\U4ee5\U540e\U7ed9\U6211\U8dea\U4e0b\U6211\U90fd\U4e0d\U8ba9\U4f60\U5438"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 185969; objectName = "\U5341\U4e8c\U4f4d\U65b0\U8001\U9999\U6e2f\U6b4c\U624b\U9f50\U805a\Uff0c\U7ecf\U5178\U91cd\U73b0\U300a\U94c1\U8840\U4e39\U5fc3&\U4e16\U95f4\U59cb\U7ec8\U4f60\U597d\U300b"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 183339; objectName = "\U4e0d\U8981\U628a\U6211\U5bf9\U4f60\U597d\Uff0c\U5f53\U4f5c\U662f\U7406\U6240\U5f53\U7136\Uff01"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 185073; objectName = "Ta\U7ba1\U4f60\U4e0d\U662f\U9650\U5236\U4f60\U800c\U662f\U56e0\U4e3aTa\U7231\U4f60\Uff0c\U8fd9\U4e2a\U793e\U4f1a\U6ca1\U6709\U8c01\U4e49\U52a1\U5bf9\U4f60\U597d\Uff0c\U5982\U679c\U4f60\U78b0\U5230\U4e86\Uff01\U8bf7\U73cd\U60dc\Uff01"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 185402; objectName = "\U5f53\U674e\U7389\U521a\U9047\U89c1\U5c0f\U9ec4\U4eba\Uff0c\U5347\U7ea7\U7248\U300a\U521a\U597d\U9047\U89c1\U4f60\U300b\U5c45\U7136\U8fd9\U4e48\U840c\U8fd9\U4e48\U597d\U542c\Uff01"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 185439; objectName = "\U4eca\U5929\U5929\U6c14\U5f88\U597d \U4f60\U4eec\U8fd8\U597d\U561b\Uff1f"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 185514; objectName = "\U5f53\U4f60\U7684T\U6064\U592a\U65e7\U4e86\U7a7f\U4e0d\U4e86\U600e\U4e48\U529e\Uff1f\U51e0\U4e2a\U975e\U5e38\U6709\U521b\U610f\U7684\U597d\U65b9\U6cd5\Uff0c\U9a6c\U4f4f\U4ee5\U540e\U8bd5\U8bd5\Uff01"; objectType = VideoPlat; }, { IsPackage = 0; PlatNum = 1; objectId = 183689; objectName = "\U5f20\U5b66\U53cb\U3001\U9648\U6167\U5a34\U7ca4\U8bed\U60c5\U6b4c\U6df1\U60c5\U5bf9\U5531\U300a\U8f7b\U629a\U4f60\U7684\U8138\U300b\Uff0c\U592a\U597d\U542c\U4e86\Uff01"; objectType = VideoPlat; } ); result = 1; } image

lixiaoyu commented 6 years ago

发现不是YYModel的问题,貌似是我工程中某个第三方的原因,导致category的操作都报这个错

semnyqu commented 6 years ago

哪个第三方库导致,能说明下使用场景吗,我也碰到类似的

lixiaoyu commented 6 years ago

是因为YYModl的这个yy_modelArrayWithClass是category方法,在我的工程中没有被链接加载,在Other-link-Flag中加入$(inherited)就行,涉及到Linker的一些知识

The "selector not recognized" runtime exception occurs due to an issue between the implementation of standard UNIX static libraries, the linker and the dynamic nature of Objective-C. Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.

Objective-C的链接器并不会为每个方法建立符号表,而是仅仅为类建立了符号表。这样的话,如果静态库中定义了已存在的一个类的分类,链接器就会以为这个类已经存在,不会把分类和核心类的代码合起来。这样的话,在最后的可执行文件中,就会缺少分类里的代码,这样函数调用就失败了。

darkfiredarkhalo commented 8 months ago

是因为YYModl的这个yy_modelArrayWithClass是category方法,在我的工程中没有被链接加载,在Other-link-Flag中加入$(inherited)就行,涉及到Linker的一些知识

The "selector not recognized" runtime exception occurs due to an issue between the implementation of standard UNIX static libraries, the linker and the dynamic nature of Objective-C. Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.

Objective-C的链接器并不会为每个方法建立符号表,而是仅仅为类建立了符号表。这样的话,如果静态库中定义了已存在的一个类的分类,链接器就会以为这个类已经存在,不会把分类和核心类的代码合起来。这样的话,在最后的可执行文件中,就会缺少分类里的代码,这样函数调用就失败了。

还需要-ObjC