开发者

passing argument 1 from incompatible pointer type

Why does this code...:

NSDictionary *testDictionary = [NSDictionary dictionaryWithObjectsAndKeys:kABOtherLabel, @"other", kABWorkLabel, @"work", nil];
// There are 9 more key-value pairs that i've omitted here.

throw this warning:开发者_StackOverflow中文版

warning: passing argument 1 of 'dictionaryWithObjectsAndKeys' from incompatible pointer type

Incidentally, the code works as expected, but I don't like leaving warnings un-delt-with. I assume it doesn't like that I'm storing a constant in a dictionary. Well, where can I store it then? Should I just place (void *) before every constant?


On the iPhone, kABOtherLabel is a CFStringRef and not an NSString *. However, the two are toll-free bridged, so you can just cast it to NSString *:

NSDictionary *testDictionary = [NSDictionary dictionaryWithObjectsAndKeys:(NSString *)kABOtherLabel, @"other", (NSString *)kABWorkLabel, @"work", nil];

(Also, you may have your keys and values reversed in this call, unless you want your literal strings to be the keys (objects come first)).


I believe that kABOtherLabel is a constant integer which is not an object. If you want to add it as an object use something along with lines of [NSNumber numberWithInteger:kABOtherLabel] (same goes for second value object)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜