基于int数的键的对象

时间:2011-10-31 22:29:35

标签: iphone objective-c

int number = 3;

NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:
                               @"Apple",[NSNumber numberWithInt:0],
                               @"Peach",[NSNumber numberWithInt:1],
                               @"Lemon",[NSNumber numberWithInt:2],
                               @"Pineapple",[NSNumber numberWithInt:3],
                               ........................,
                               nil];

NSString *numberToKey = [dict objectForKey:number];

如何在字符串中插入基于int number的dict值?

1 个答案:

答案 0 :(得分:3)

将值放入字典的方式相同:

NSString *numberToKey = [dict objectForKey:[NSNumber numberWithInt:number]];