在ios开发中创建了类别扩展的文件,但总是识别扩展的原文件方法,在动态调用扩展方法时出现unrecognized selector sent to instance错误,看到国外网站的一个解决办法:
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.
To resolve this issue, the target linking against the static library must pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes.
Important: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes. The workaround is to use the -all_load or -force_load flags.
大体意思是:categories的类在Xcode中无法识别,需要添加链接参数,具体为:Build Settings->other linker flags加入-ObjC或者-all_load。