If I had an NSDictionary like this:
NSMutableDictionary *valuesDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:-60.0],@”a”,
[NSNumber numberWithDouble:0.0],@”b”,
[NSNumber numberWithDouble:-12.0],@”c”,
[NSNumber numberWithDouble:.3],@”x”, nil];
and an array like this:
NSArray *program = [NSArray arrayWithObjects: @"a",@"12.6",@"100",@"+",@"x",nil];
what would the code look like to return an array programWithVariableValues, for example, consisting of @”-60″,@”12.6″,@”100″,@"+",@”.3″,nil?
(replacing any variables found in the array with their valueforkey’s)
Would that be a good place to utilize NSPredicate? or just fast enumeration? or something else?
There may be a clever one-liner solution using predicates and/or valueForKeyPath operators, but until somebody figures that one out, this should do the trick:
The programWithVariableValues array now contains your values (as strings). If you'd prefer to keep the numbers as NSNumbers, take out the "[... description]" call.