Reputation: 11
I was curious to know if I can use an NSArray within a NSMutableDictionary when declaring values for a variable. Because the app that I am coding required multiple instances of variable to equal about four or five floats. I don't want to have to write it like:
- (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"];
I'm sure there is a way to declare a set of values to one variable but I am beginner at this language and I was hoping for a bit of help. Any tips?
Upvotes: 1
Views: 202
Reputation: 48398
Yes. You can use any subclass of NSObject
, including NSArray
or NSMutableArray
, for an NSDictionary
or NSMutableDictionary
.
Upvotes: 5