如何使用整数值作为'key'在NSMutableDictionary中设置浮点值?
答案 0 :(得分:6)
使用NSNumber
literals,您可以执行以下操作
[dict setObject:@5.562 forKey:@5];
//or
int key = 5;
float value = 5.562;
[dict setObject:@(value) forKey:@(key)];
并检索:
float retrVal = [[dict objectForKey:@5] floatValue];