Quick Hits: Why Can’t I Call the Methods on This Objective-C Category?

The scenario: You have a category on a common class – like say, AFNetworking‘s category to make UIImageView load images asynchronously from a URL. The category source lives in a static library that you’re linking into your main project. (You may, as I do, have the library as a subproject of your actual project.) You attempt to call a method on the category, and you get the dreaded "unrecognized selector sent to instance". You know you’re linking the file into the static library correctly, and that you’re linking the static library into your project.

Before you commence wailing and gnashing your teeth, add -all_load to the “Other Linker Flags” build setting in your main project. Worked for me.

Thanks are due to Dave DeLong for answering this SO question, because otherwise I’d have probably spent the rest of the day wailing, gnashing my teeth, and ignorantly trying build options until something worked.

Note that the relevant docs make this feel kind of kludgy – but I need software that works today, you know?

This entry was posted in iOS, iPhone, Quick Hits, Xcode and tagged , , , , , . Bookmark the permalink.