Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Use Multi Value Title and Value From Settings Bundle

I have a multi value setting (location) defined in my settings bundle for an app.
The Titles are defined as long titles, for example, "London" and the corresponding value part of the setting is defined as "1".

[EDIT]

To expand this question I will add more information about the multi value setting:

this is a screenshot of the multi value setting

How do I retrieve the Title of LONDON at Item 0. As described above when I retrieve the objectForKey or valueForKey I get 1 always. I want to display the string "LONDON" from the title in a label in the app but use the value 1 in core data. Note: I have set the value in the settings before the app runs so it does return a value but the value is always 1 as the Title does not seem to be accessible.

like image 917
motionpotion Avatar asked May 08 '13 22:05

motionpotion


3 Answers

You should set your "Default Value" value as "1" - Just Item 0 from your "Values" list.

like image 142
Alexander Slabinsky Avatar answered Nov 19 '22 02:11

Alexander Slabinsky


I ran into the similar situation and answering the question that it'll help someone.

If I understand the question correctly, when user selects London from the settings the default value will be 1. when you read the settings bundle for locationSetting you get the value 1 and not LONDON, but you want the "LONDON" in your code rather than 1. It is not possible with the current structure of your plist. make the default value a dictionary instead of string and then you can have both titles and values inside that dictionary. you can then retrieve the text of the selected value.

like image 6
Tamil Avatar answered Nov 19 '22 01:11

Tamil


Location settings as a multi value, is an NSDictionary. Therefore, do the following:

NSDictionary *location = [[NSUserDefaults standardUserDefaults] valueForKey:@"locationSettings"]; 

NSString *value = (NSString *)location; 

Cast the location value as a NSString because you know a string is to be returned.

You can then handle the result as a string. The "value" variable returned is whatever is written in the value section. In your case, if you select "London", you will get a value of "1" back in the form of a string.

like image 2
jheneghan Avatar answered Nov 19 '22 03:11

jheneghan