我创建了一个类似以下的NSDictionary:
NSArray * alphabets = [NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j",@"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s",@"t",@"u",@"v",@"w",@"x",@"y",@"z",nil];
alphaToNum = [NSMutableDictionary dictionary];
numToAlpha = [NSMutableDictionary dictionary];
for(NSString* character in alphabets)
{
[alphaToNum setObject:[NSNumber numberWithInteger:index] forKey:character];
[numToAlpha setObject:character forKey:[NSNumber numberWithInteger:index]];
index++;
}
现在我想访问“numToAlpha”,如下所示:
NSInteger code1;
NSNumber * nn = [numToAlpha objectForKey:code1];
我会得到错误,而在objectforkey的手册中它清楚地说(id)objectforkey(id)这意味着什么!
答案 0 :(得分:2)
NSInteger
不是对象。 id
指的是任何对象类型。您需要在代码示例中使用[NSNumber numberWithInteger:code1]
。