Saturday, 7 September 2013

Increment the key in an NSDictionary

Increment the key in an NSDictionary

Hi I'm assigning items to a dictionary but I'm trying to get the key of
the dictionary to increment but I keep on getting the same value.
I try to increment the NSNumber:
int origNumber = 1; origNumber+=1;
NSNumber *number = [NSNumber numberWithInt:origNumber];
int numToInc = [number intValue];
number = [NSNumber numberWithInt:numToInc];
//Then I'm adding to the Dictionary:
[dictionary setObject: object forKey:number];
my ouput is always:
2 for the key.

No comments:

Post a Comment