开发者

cocoa objective-c NSDictionary with integer objects

开发者 https://www.devze.com 2023-02-10 12:49 出处:网络
Why does dict2 show a warning about its object not being a pointer when dict开发者_开发百科1 shows no such warning?

Why does dict2 show a warning about its object not being a pointer when dict开发者_开发百科1 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];


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 */


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

0

精彩评论

暂无评论...
验证码 换一张
取 消