Calling method on category included from iPhone static library causes NSInvalidArgumentException

前端 未结 9 707
粉色の甜心
粉色の甜心 2020-12-04 10:36

I have created a static library to house some of my code like categories.

I have a category for UIViews in \"UIView-Extensions.h\" named Extensions.

In this

9条回答
  •  隐瞒了意图╮
    2020-12-04 11:29

    Unfortunately, due to the what categories work and the dynamic nature of the Objective-C runtime, not everything works well with static libraries. The reason you get this error is that the category implementation in the static library is never actually linked into the executable image because the compiler has no way of knowing that the implementation code will be needed at run-time.

    In order to cure this, you can force the linker to copy object files from a static archive for any and all Objective-C Class and Category images. The downside is that your executable will include image code for classes that you may not be using at all. To get the linker to include the category code, add -ObjC to the OTHER_LD_FLAGS build setting in Xcode. Your category implementation will now be copied from the static archive to your executable and you won't get the runtime exception.

提交回复
热议问题