Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将NSArray存储在NSDictionary中?_Iphone_Objective C_Nsarray_Nsdictionary - Fatal编程技术网

Iphone 如何将NSArray存储在NSDictionary中?

Iphone 如何将NSArray存储在NSDictionary中?,iphone,objective-c,nsarray,nsdictionary,Iphone,Objective C,Nsarray,Nsdictionary,我试着自学,但却在努力学习如何将NSArray之类的东西存储在NSDictionary中 假设你有一本食谱词典: 假设NSDictionary有如下键: 意大利面, 费图辛·阿尔弗雷多, 烤鸡沙拉 《国家科学院词典》有一个NSArray,它只是一个成分列表 我认为等效的PHP代码类似于: $['Spaghetti'] = array('Spaghetti Pasta', 'Spaghetti Sauce', 'Meatballs'); $['Fettucine Alfredo'] = array

我试着自学,但却在努力学习如何将NSArray之类的东西存储在NSDictionary中

假设你有一本食谱词典:

假设NSDictionary有如下键:

意大利面, 费图辛·阿尔弗雷多, 烤鸡沙拉

《国家科学院词典》有一个NSArray,它只是一个成分列表

我认为等效的PHP代码类似于:

$['Spaghetti'] = array('Spaghetti Pasta', 'Spaghetti Sauce', 'Meatballs');
$['Fettucine Alfredo'] = array('Fettucine Pasta', 'Alfredo Sauce');
$['Grilled Chicken Salad'] = array('Lettuce', 'Grilled Chicken', 'Croutons');
我正在努力解决如何将NSArray添加到NSDictionary中的问题。那么,如果我想删除一个元素或向数组中添加一个元素,该怎么办?如何检索、删除或添加到

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];
可以将任何对象类型作为值添加到字典中。有关词典的更多信息,请参阅