Question

I`m planning to use the titles in a PSMultiValueSpecifier from settings.bundle in a pickerview. I only know how to get my selected value based on the key from the settings.bundle. Is it possible to get ALL titles based on the key ?

Was it helpful?

Solution

Here is my version which also uses the specifier KEY to locate the PSMultiValueSpecifier without remembering at which index is it located. Indexes might change over time (due to changes in the settings bundle).

NSString* settingsBundle = [[[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"] stringByAppendingPathComponent:@"Root.plist"];

NSDictionary* rootPlist = [NSDictionary dictionaryWithContentsOfFile:settingsBundle];

if (rootPlist == nil)
    return nil;

NSArray* specifiers = [rootPlist objectForKey:@"PreferenceSpecifiers"];

NSDictionary *multiValueSpecifier = nil;

for (NSDictionary *specifier in specifiers)
{
    if ([[specifier objectForKey:@"Key"] isEqualToString:speficierKey] == YES &&
        [[specifier objectForKey:@"Type"] isEqualToString:@"PSMultiValueSpecifier"] == YES)
    {
        multiValueSpecifier = specifier;
        break;
    }
}

if (multiValueSpecifier == nil)
    return nil;

NSArray* titlesArray = [multiValueSpecifier objectForKey:@"Titles"];
NSArray* valuesArray = [multiValueSpecifier objectForKey:@"Values"];

NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:titlesArray 
                                                       forKeys:valuesArray];

return dictionary;

OTHER TIPS

(May be there's more elegant way). You can get settings dictionary and browse its contents (provided you know its internal structure):

NSString* listPath = [[[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"] stringByAppendingPathComponent:@"Root.plist"];
NSDictionary* ttDict = [NSDictionary dictionaryWithContentsOfFile:listPath];
if (ttDict != nil){
    NSArray* prefsArray = [ttDict objectForKey:@"PreferenceSpecifiers"];
    // Next you get dictionary for required setting by its index (you should know it)
    NSDictionary* settingDict = [prefsArray objectAtIndex: index];
    NSArray* titlesArray = [settingDict objectForKey:@"Titles"]; // Voila
}

Note that titles you get this way are not localized.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top