Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It was stated in another answer (so I upvoted that one), but maybe an example would help.</p> <pre><code>NSMutableDictionary *myExpenses = [[NSMutableDictionary alloc] init]; while (enterMore == 1) { Expense *anExpense = [[Expense alloc] init]; NSLog(@"Enter an expense:\n\nName: "); scanf("%s", expenseName); billName = [NSString stringWithUTF8String: expenseName]; anExpense.name = billName; NSLog(@"\nEnter the amount of the expense: "); scanf("%lf", &amp;expenseAmount); anExpense.amount = expenseAmount; NSLog(@"\nEnter the day of the month the expense is due: "); scanf("%d", &amp;dateDue); anExpense.dayOfMonthDue = dateDue; [myExpenses setObject:anExpense forKey:billName]; NSLog(@"Enter 1 to enter more expenses anything else to quite: "); scanf("%d", &amp;enterMore); } NSArray * allValues = [myExpenses allValues]; for (int i = 0; i &lt; [allValues count]; i++) { Expense * myExpense = [allValues objectAtIndex:i]; NSLog(@"%@", [myExpense name]); NSLog(@"%f", [myExpense amount]); NSLog(@"%d", [myExpense dayOfMonthDue]); } </code></pre> <p>The real power is that now, you can reference a value <em>by name</em>. For example:</p> <pre><code>Expense * anExpense = [myExpenses objectForKey:@"Expense Name"]; </code></pre> <p>Hopefully this helps.</p> <p>EDIT: Also, I notice you are not calling <code>-release</code> or <code>-autorelease</code> on your instances. You're either using ARC (Automatic Reference Counting) or if you're still using MRR (Manual Retain-Release), you should be autoreleasing your Expenses. If you are using ARC, don't mind this, but if not - You will have memory leaks. Or you can explicitly call release (See: <a href="https://stackoverflow.com/questions/1147785/use-autorelease-before-adding-objects-to-a-collection">Use autorelease before adding objects to a collection?</a>)</p>
 

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