这是我的代码
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];
NSMutableDictionary * alphaToNum = [NSMutableDictionary dictionary];
NSInteger index =0;
for (NSString * character in alphabets) {
index++;
[alphaToNum setObject:character forKey:[NSNumber numberWithInteger:index]];
}
NSLog(@"%@",[alphaToNum objectForKey:@"d"]);
每次我尝试为我的 key 获取一些值时,我只得到 0 。
最佳答案
你需要...
NSLog(@"%@",[alphaToNum objectForKey:[NSNumber numberWithInteger:[alphabets indexOfObject:@"d"]]]);
关于iphone - 从 NSDictionary 我只得到 0 或 null 我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7874648/