Saturday, January 14, 2012

Build Dictionary with Array inside


   
NSMutableDictionary *dict11 = [[NSMutableDictionary alloc] init];
// init two array with elements
NSArray *md = [[NSArray alloc] initWithObjects:@"TFT", @"STN", @"OLED", nil];
NSArray *dss = [[NSArray alloc] initWithObjects:@"LED", @"power", nil ];

// init dictionary with Array and key
dict11 = [NSDictionary dictionaryWithObjectsAndKeys: md, @"MD", dss, @"DSS", nil];

// dump key into console
for (id key in dict11) NSLog(@"%@ - %@", key, [dict11 objectForKey:key]);

// init NSArray with objects with "MD" key
NSArray *array1 =[[NSArray alloc] initWithObjects:[dict11 objectForKey:@"MD"],nil];

// dump the NSArray content to console
for (id str in array1) NSLog(@"array1 -%@", str);
   

No comments:

Post a Comment