Sridatta Thatipamala
Sridatta Thatipamala

Reputation: 2222

JSONKit unrecognized selector while serializing

I am trying to use the JSONKit library and have included the source files in my project. I have included the JSONKit.h header so that the included category gives NSDictionary objects the JSONData and JSONString selectors.

  NSMutableDictionary* root = [NSMutableDictionary dictionary];
  [root setValue:@"CONNECT" forKey:@"command"];
  NSData* data = [root JSONData];

But at runtime I get the following error:

 -[__NSCFDictionary JSONString]: unrecognized selector sent to instance 0x784b870

Why is the category not adding the appropriate methods to NSDictionary objects?

Upvotes: 2

Views: 1338

Answers (3)

Abhi Beckert
Abhi Beckert

Reputation: 33349

It's a bit of a n00b error, but I ran into exactly the same exception when I imported the JSONKit.h and JSONKit.m files into my project, but did not tick the box to add it to the target in Xcode.

Open JSONKit.m, show the File Inspector section of the Utilities panel, and in the Target Membership make sure there is a box ticked next to your app.

Upvotes: 0

Madbreaks
Madbreaks

Reputation: 19539

While the accepted answer resolved the issue for me, understanding why it did (and why it might not) is definitely useful. For a more detailed look at this issue and possible solutions, see this post.

Upvotes: 0

Sridatta Thatipamala
Sridatta Thatipamala

Reputation: 2222

I'm answering my own question because I just figured it out.

My code is part of a static library that is being referenced from another iOS application. When including a static library that exports categories, the application that is using the category must be linked with the "-ObjC" linker flag.

Upvotes: 3

Related Questions