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:
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.
You should set your "Default Value" value as "1" - Just Item 0 from your "Values" list.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With