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 *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">