flashsnake
flashsnake

Reputation: 562

Getting strange error in NSDictionary

I am getting strange exception when calling the NSDictionary in the following example:

NSInteger userId = 1;
NSDictionary *postData = [NSDictionary dictionaryWithObjectsAndKeys:
                      @"3", @"a",
                      @"0", @"b",
                      userId, @"c",
                      nil];

Can someone see what's the problem above?

Upvotes: 0

Views: 40

Answers (1)

Jack
Jack

Reputation: 133557

NSDictionary, as most collections, just accepts real Obj-C objects (id type), but you are passing a NSInteger which is a normal C typedef.

Try with NSNumber userId = [NSNumber numberWithInt:1];

Upvotes: 2

Related Questions