tags:

views:

38

answers:

2

Hi there.

i have been working on plist these days and got stuck in adding a key to plist which has a boolean value. Here is my plist structure.

Root (Dictionary)
+- Parent1 (Dictionary)
   - Key1 (Boolean)
   - Key2 (Boolean)
   - Key3 (Boolean)

+- Parent2 (Dictionary)
   - Key1 (Boolean)
   - Key2 (Boolean)

Suppose now i want to add another key (key4) which is also Boolean to Parent1, how can i do that?

Thanks for the help

A: 

Got myself the answer. If someone is looking for something like this, here is how to do it.

NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSMutableDictionary *dict2 = [dict objectForKey:@"dict2"];
NSNumber *batteryBool = [NSNumber numberWithBool:TRUE];
[dict2 setObject:batteryBool forKey:@"Key4"];
[dict setValue:dict2 forKey:@"dict2"];
[dict writeToFile:plistPath atomically:YES];
raziiq
+1  A: 

NSDictionary does only take references to objects, therefore, you can't directly pass a bool (since it is not a reference). Instead you could use the following:

[NSNumber numberWithBool:NO]

or

[NSNumber numberWithBool:YES]
dkk