I have a couple of questions regarding the code below:
(1) Is "newItem" an autoreleased object? Its getting a returned dictionary from the specified array index?
(2) Is there a simple way to access an array of dictionarys in one hit, or am I doing it the way you would expect?
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableArray *menu = [[NSMutableArray alloc] init];
NSMutableDictionary *menuItem;
NSMutableDictionary *newItem;
NSArray *itemName = [NSArray arrayWithObjects:
@"Latte Medio",
@"Cappucion Medio",
@"Mocha Medio",
@"Vanilla Latte Medio",nil];
NSArray *itemFat = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:6.9],
[NSNumber numberWithFloat:4.7],
[NSNumber numberWithFloat:6.6],
[NSNumber numberWithFloat:6.9],nil];
NSArray *itemCals = [NSArray arrayWithObjects:
[NSNumber numberWithInt:516],
[NSNumber numberWithInt:408],
[NSNumber numberWithInt:624],
[NSNumber numberWithInt:743],nil];
NSLog(@"DICTARRAY ... Start");
// Create menuItem object
menuItem = [[NSMutableDictionary alloc] init];
[menuItem setObject:[itemName objectAtIndex:0] forKey:@"product"];
[menuItem setObject:[itemFat objectAtIndex:0] forKey:@"fat"];
[menuItem setObject:[itemCals objectAtIndex:0] forKey:@"calories"];
// Add menuItem object to menu
[menu addObject:menuItem];
[menuItem release], menuItem = nil;
// Access menu to get menuItem
newItem = [menu objectAtIndex:0];
NSLog(@"DATA: %@",[newItem objectForKey:@"product"]);
NSLog(@"DATA: %@",[newItem objectForKey:@"fat"]);
NSLog(@"DATA: %@",[newItem objectForKey:@"calories"]);
// Clean up
[menu release], menu = nil;
[pool drain];
return 0;
}
gary