Reputation: 58067
I'm getting a compiler warning when using the following code:
for(int i=0; i<[mutableTempArray count]; i++){
//...
[tempInfoDictionary setValue:i forKey:@"tag"];
//...
}
The warning is:
passing argument 1 of 'setValue:forKey:' makes pointer from integer without a cast
What am I doing wrong here?
Upvotes: 1
Views: 658
Reputation: 163228
Collections in Objective-C can only hold objects, so you'll need to wrap i
in an NSNumber
object.
i
itself is a primitive type, not an object, so it can't be put inside a collection object.
The first argument to setValue:forKey:
is expected to be of pointer type, which i
itself clearly isn't.
I suggest using the setObject:forKey:
method on an NSDictionary
instead of setValue:forKey:
, because it states your intentions better. You're not only storing a value, you're storing an object
[tempInfoDictionary setObject:[NSNumber numberWithInt:i] forKey:@"tag"];
Upvotes: 6
Reputation: 3376
You're trying to put an int
into an object array, but it's expecting an id
i.e. a pointer. Try [tempInfoDictionary setValue:[NSNumber numberWithInt:i] forKey:@"tag"];
Upvotes: 1