Hi EveryOne,
My query is regarding the settings bundle. I hve hve created the settings bundle with one group which consists on a textfeild, multivalue and a boolean. When make the rootfile it appears properly into the setting apps.
Next step was to configure ur NSUserDefault which i configured according to the root.plist but while initializing with boolean value its giving me an error also when i m tring to retrieve the value (boolean) from the root.plist its gve me the error of incompatible types.
i show the code which i hve written fr clarification
//code is here
NSString *testValue = [[NSUserDefaults standardUserDefaults] stringForKey:kLastNameKey];
//testValue = nil;
if (testValue == nil)
{
// no default values have been set, create them here based on what's in our Settings bundle info
NSString *pathStr = [[NSBundle mainBundle] bundlePath];
NSString *settingsBundlePath = [pathStr stringByAppendingPathComponent
"Settings.bundle"];
NSString *finalPath = [settingsBundlePath stringByAppendingPathComponent
"Root.plist"];
NSDictionary *settingsDict = [NSDictionary dictionaryWithContentsOfFile:finalPath];
NSArray *prefSpecifierArray = [settingsDict objectForKey
"PreferenceSpecifiers"];
NSString *lastNameDefault;
NSNumber *nameColorDefault;
Boolean *iPodSoundDefault;
NSDictionary *prefItem;
for (prefItem in prefSpecifierArray)
{
NSString *keyValueStr = [prefItem objectForKey
"Key"];
id defaultValue = [prefItem objectForKey
"DefaultValue"];
if ([keyValueStr isEqualToString:kLastNameKey])
{
lastNameDefault = defaultValue;
}
else if ([keyValueStr isEqualToString:kNameColorKey])
{
nameColorDefault = defaultValue;
}
else if ([keyValueStr isEqualToString:kPlay_sound_preference])
{
iPodSoundDefault = defaultValue;
// on this statement i get the warning of incompatible value
//but i hve put value as Boolean in the root.plist file for this key.
}
}
// since no default values have been set (i.e. no preferences file created), create it here
NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys:
lastNameDefault, kLastNameKey,
[NSNumber numberWithInt:1], kNameColorKey,
TRUE, kPlay_sound_preference,
nil];
//Here it gives the runtime error for the boolean value
//Becuase whn i made other rpject without boolean value everything was
//working properly but in this project whn i used boolean value fr toggle //switch problem started occuring
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];
}
// we're ready to do, so lastly set the key preference values
self.lastName = [[NSUserDefaults standardUserDefaults] stringForKey:kLastNameKey];
self.textColor = [[NSUserDefaults standardUserDefaults] integerForKey:kNameColorKey];
self.iPodSound = [[NSUserDefaults standardUserDefaults] boolForKey:kPlay_sound_preference]