storing variable values in NSMutableDictionary

1.9k Views Asked by At

we do have a calculator app in ios5 and we want the users to set their own values to our calculators variable buttons such as "x" or "y". For example the user set "x=5" and wants to do the calculation of" x + 5 = " the result should be 10 anyway.how do we make the program store the temporary values of variable defined by user in an NSMutableDictionary

1

There are 1 best solutions below

0
On

Create the NSMutableDictionary, convert the number to an NSNumber and put it into the NSMutableDictionary.

NSMutableDictionary *customValues = [NSMutableDictionary dictionary];

float value = 5;

NSNumber *number = [NSNumber numberForFloat:value];
[customValues setObject:number forKey:@"x"];

or using literals replace the above two lines with:

customValues[@"x"] = @(value);

Or are you asking a different question?