Calling method on category included from iPhone static library causes NSInvalidArgumentException Calling method on category included from iPhone static library causes NSInvalidArgumentException xcode xcode

Calling method on category included from iPhone static library causes NSInvalidArgumentException


The only solution that worked was to include:

"-all_load"

in other linker flags.

EDIT: Be sure to add this flag to the project including the static library, not to the static library itself.

I know this isn't the correct method, but it is working for now.

It maybe a OS 3.0 issue since this was the work around for Three20 as well.


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 Xcode 4. 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.