How to write BOOL plist?

I would like to assign the boolean value of the plist file entry. I do the following:

NSString *aBool = realBoolValue ? @"YES" : @"NO"; [myplist setValue: aBool forKey:@"boolKey"]; [myplist writeToFile: [NSHomeDirectory() stringByAppendingPathComponent: plistFilePath] atomically:NO]; 

But an appointment is never required. I am doing this because the following does not 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"]; 
+4
source share
2 answers

You can wrap it in an NSNumber object:

  [NSNumber numberWithBool:yourBool] 

Use [NSNumber boolValue] when reading a value from plist.

+16
source
 [NSNumber numberWithBool:yourBool] 

If you do, you will get a number when you call objectForKey@ "boolKey" . But if you add bool for the key to the plist file, you will get NSCFBoolen .

0
source

All Articles