How to store NSArray in NSDictionary?

I'm trying to teach myself, but struggling with how to store something like NSArray inside an NSDictionary.

Suppose you had an NSDictionary for recipes:

Let's say in NSDictionary there were such keys as:

Spaghetti, Fettusin Alfredo, Grilled Chicken Salad

And in NSDictionary was NSArray, which was just a list of ingredients.

I assume that the equivalent PHP code would be something like this:

$['Spaghetti'] = array('Spaghetti Pasta', 'Spaghetti Sauce', 'Meatballs');
$['Fettucine Alfredo'] = array('Fettucine Pasta', 'Alfredo Sauce');
$['Grilled Chicken Salad'] = array('Lettuce', 'Grilled Chicken', 'Croutons');

I am struggling with how to add NSArray to NSDictionary. Then what if I wanted to delete an element or add an element to an array? How is it extracted and removed or added?

+5
source share
1 answer
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
  [NSArray arrayWithObjects:@"Spaghetti Pasta", @"Tomato Sauce", nil], @"Spaghetti",
  [NSArray arrayWithObjects:@"Fettuccine Pasta", @"Alfredo Sauce", nil], @"Fettuccine Alfredo",
  [NSArray arrayWithObjects:@"Lettuce", @"Grilled Chicken", @"Croutons", nil], @"Grilled Chicken Salad",
  nil];

. . documentation.

+9

All Articles