Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing an Array of Dictionarys?
    primarykey
    data
    text
    <p>I have a couple of questions regarding the code below:</p> <p>(1) Is "newItem" an autoreleased object? Its getting a returned dictionary from the specified array index?</p> <p>(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?</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; 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; } </code></pre> <p>gary</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload