由于NSDictionary仅设计用于处理对象,因此一种简单的方法是将整数包装并浮在NSNumber对象中.例如:
NSMutableDictionary *testDictionary = [[NSMutableDictionary alloc] init];
[testDictionary setObject:[NSNumber numberWithFloat:1.23f]
forKey:[NSNumber numberWithInt:1]];
NSLog(@"Test dictionary: %@", testDictionary);
[testDictionary release];
要提取相关值,只需从NSNumber类中使用适当的intValue、floatValue等方法.