I use the codes below to read and write a bool value from my application:
-(void)SaveAppSetting;
{
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
bool b=true;
[defaults setBool:b forKey:@"AnyKey"];
[defaults synchronize];
}
-(void)LoadAppSetting;
{
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
bool b=[defaults boolForKey: @"AnyKey"] ;
}
I found that “LoadAppSetting” worked well, it could get the correct value of item with key “AnyKey”.
The function “SaveAppSetting” looked like no function, it reported no error, but it can not change value of the item with key “AnyKey”.
“AnyKey” setting in Setting bundle is
item Dictionary
Type String PSToggleSwitchSpecifier
Title String AnyKey's Title
Key String AnyKey
DefaultValue Boolean Checked
Is there any person met the same problem?
Thanks interdev
Have you tried using the BOOL type. I am not 100% sure they are exactly the same. BOOL is a char type and I think bool is int.
Really should not make a difference as type conversion should happen. For what it is worth, I use the following to get a BOOL out:
I Sync at a later point to avoid frequent writes.