Get/Set a BOOL in the NSDictionary

Objective-C containers can store only Objective-C objects so you need to wrap you BOOL in some object.

Here is the Dictionary
NSMutableDictionary *dictionary1 =[[NSMutableDictionary alloc]init];
[dictionary1  setObject:[NSNumber  numberWithBool:false]  forKey:@"MyBoolValue"];

How to set bool value ?
[dictionary1  setObject:[NSNumber  numberWithBool:false]  forKey:@"MyBoolValue"];

How to get bool value ?
BOOL myValue = [dictionary1  objectForKey:@"MyBoolValue"]  boolValue];

沒有留言: