Objective-C category is not loaded - How to debug this

冷暖自知 提交于 2019-12-10 13:17:04

问题


I have two projects which the RestKit framework.

One project works without problems but another project fails, as soon as the RestKit framework is used.

I found out that the failing code is this:

return [anNSString MD5];

The MD5 method is a category method and is imported like this:

#import "NSString+MD5.h"

However, in one project, I keep getting the following error:

-[__NSCFString MD5]: unrecognized selector sent to instance 0x88a3390

I understand the basics of categories, and that they can be loaded at runtime, but I don't see why the category does not get loaded in this case.

These are the files on github: NSString+MD5.m, NSString+MD5.h,


回答1:


Make sure you have the -ObjC flag enabled. Or it will not link categories in a static library.

Objective-C categories in static library




回答2:


It's not enough to just include the header file. You also need to compile and link the .m file in your project.



来源:https://stackoverflow.com/questions/8714746/objective-c-category-is-not-loaded-how-to-debug-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!