Search code examples
iphoneobjective-cioscategoriesgoogle-toolbox-for-mac

Unrecognized selector on calling Google Toolbox for Mac NSString category method in iOS


I'm building a static library for use in an iOS project, and I want to decode XML entities returned from a web service. I've grabbed Google Toolbox for Mac and added the following files to my project:

  • GTMDefines.h
  • GTMNSString+HTML.h
  • GTMNSString+HTML.m

Then in my own .m file I'm doing this:

#import "GTMNSString+HTML.h"

// then in one of my methods:
NSString *value = [anotherNSStringValue gtm_stringByUnescapingFromHTML];

The code compiles fine, but when I run the app that uses my static library it crashes with a NSInvalidArgumentException, complaining that the gtm_stringByUnescapingFromHTML selector isn't recognised for NSString:

2011-02-10 12:21:38.401 MyApp[20356:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString gtm_stringByUnescapingFromHTML]: unrecognized selector sent to instance 0x71403e0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0111bbe9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x012705c2 objc_exception_throw + 47
    2   CoreFoundation                      0x0111d6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x0108d366 ___forwarding___ + 966
    4   CoreFoundation                      0x0108cf22 _CF_forwarding_prep_0 + 50
    5   MyApp                               0x00028dcf -[GSMyAppXMLParser parseData:] + 714
    // Rest of stack trace removed
)
terminate called after throwing an instance of 'NSException'

I've found a few similar issues on Stack Overflow, and in each case the questioner has subsequently commented that they fixed it by tweaking a linker setting - but without disclosing which setting! If anyone can help me with this I'd be forever grateful!


Solution

  • I’m guessing that would be the -ObjC and -all_load flags.

    You add these to the ‘Other Linker Flags’ of the app that links agains the library, not the library itself.

    For more info see: http://developer.apple.com/library/mac/#qa/qa2006/qa1490.html