I have set up a preference using multi_preference in my Root.plist in my Settings.bundle as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSMultiValueSpecifier</string>
<key>Key</key>
<string>multi_preference</string>
<key>DefaultValue</key>
<string>Show First Page</string>
<key>Title</key>
<string>My Option</string>
<key>Identifier</key>
<string>myOption</string>
<key>Titles</key>
<array>
<string>Option 1</string>
<string>Option 2</string>
</array>
<key>Values</key>
<array>
<string>Option 1</string>
<string>Option 2</string>
</array>
</dict>
</array>
</dict>
</plist>
When I try to get the value from the list using the following code:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *option = [defaults arrayForKey:@"myOption"];
I always get nil returned.
I am using the simulator and I have set initial values in my applications settings.
Anybody got any ideas what I have missed out?
Thanks
iphaaw
Sorry for my previous answer, I misunderstood the question. Let’s try this again.
Looking at the documentation for PSMultiValueSpecifier, the key for NSUserPreferences is stored in the “Key” key in the plist, not the “Identifier” key. So in this case,
[defaults arrayForKey:@"multi_preference"]should get you your value. Or you could change it like this and it should work with “myOption”: