Objective-C: Categories and static libraries

After taking advantage of Objective-C categories to add some additional behaviour to NSArray and NSDictionary, I decided to extract the new classes I created into a static library. However, when running my application that made use of this static library, I received the following error:

unrecognized selector sent to instance

There is an Apple tech note that explains how to resolve this – QA1490

To resolve this issue, the static library should 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*