james
james

Reputation: 26271

cocoa objective-c NSDictionary with integer objects

Why does dict2 show a warning about its object not being a pointer when dict1 shows no such warning?

Shouldn't both show this warning? both are integers..

erg.

NSDictionary *dict1 = [NSDictionary dictionaryWithObject:0 forKey:TAG_KEY];
NSDictionary *dict2 = [NSDictionary dictionaryWithObject:1 forKey:TAG_KEY];

Upvotes: 2

Views: 482

Answers (2)

Seva Alekseyev
Seva Alekseyev

Reputation: 61378

You can use class NSNumber if you want integers in the dictionary.

Upvotes: 0

Chuck
Chuck

Reputation: 237070

Obviously, ints are not objects — but 0 in a pointer context is interpreted as nil/NULL. In fact, that's precisely how nil is defined. From objc.h:

#define Nil 0           /* id of Nil class */
#define nil 0           /* id of Nil instance */

Upvotes: 5

Related Questions