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
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.
I just spoke to an Apple engineer about this, and this has been addressed in ld with versions >100. This is included in XCode4. He walked me through this and I tried it myself and indeed the category problem is fixed.
Take out "-all_load" and go back to "-ObjC" in your Build Settings with the new linker.
The issue that -all_load
or -force_load
linker flags were needed to link categories has been fixed in LLVM. The fix ships as part of LLVM 2.9 The first Xcode version to contain the fix is Xcode 4.2 shipping with LLVM 3.0. The mentioned fixes are no longer needed when working with Xcode 4.2. The -ObjC
flag is still needed when linking ObjC binaries