Iphone 基于整数的键的对象
如何在字符串中插入基于整数的dict值?与将值放入字典的方式相同:Iphone 基于整数的键的对象,iphone,objective-c,Iphone,Objective C,如何在字符串中插入基于整数的dict值?与将值放入字典的方式相同: int number = 3; NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys: @"Apple",[NSNumber numberWithInt:0], @"Peach",[NSNumber numberWithInt:
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 = 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,因为它会认为int就是指针本身;使用[NSNumber]是go.Upvote的方法。不能在需要指针类型对象的地方传入int,因为它会认为int就是指针本身;使用[NSNumber]是一种方法。