我很好奇,在声明变量的值时,是否可以在NSMutableDictionary中使用NSArray。因为我正在编写的应用程序需要变量的多个实例来等于大约四个或五个浮点数。我不想写成这样:
- (void)buildKeyMapping {
self.keyMapping = [[NSMutableDictionary alloc] initWithCapacity:9];
[keyMapping setObject:[NSNumber numberWithFloat:466.7] forKey:@"c1"];
[keyMapping setObject:[NSNumber numberWithFloat:494.4] forKey:@"c2"];
[keyMapping setObject:[NSNumber numberWithFloat:523.8] forKey:@"c3"];
[keyMapping setObject:[NSNumber numberWithFloat:415.8] forKey:@"c4"];
[keyMapping setObject:[NSNumber numberWithFloat:440.5] forKey:@"c5"];我确信有一种方法可以将一组值声明为一个变量,但我是这门语言的初学者,我希望能得到一些帮助。有什么建议吗?
发布于 2011-07-19 07:27:58
是。您可以对NSDictionary或NSMutableDictionary使用NSObject的任何子类,包括NSArray或NSMutableArray。
https://stackoverflow.com/questions/6740618
复制相似问题