I'd like to assign a boolean value to a plist file entry. I'm doing the following:
NSString *aBool = realBoolValue ? @"YES" : @"NO";
[myplist setValue: aBool forKey:@"boolKey"];
[myplist writeToFile: [NSHomeDirectory() stringByAppendingPathComponent: plistFilePath] atomically:NO];
But the assignment never takes. I'm doing the above because the following doesn't work:
[myplist setValue: realBoolValue forKey:@"boolKey"];
It gives an incompatible type error. What am I doing wrong?
-- EDIT ---
plistFilePath is initialized as
plistFilePath = [NSHomeDirectory() stringByAppendingPathComponent: @"Library/Preferences/myfile.plist"];
You can wrap it in a NSNumber object:
[NSNumber numberWithBool:yourBool]
Use [NSNumber boolValue] when reading back the value from the plist.
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