如何在NSMutableArray中从一个键NSDictionary添加对象

时间:2013-06-03 09:53:32

标签: objective-c nsmutablearray nsdictionary

我有一个NSDictionary和一个NSMutableArray我希望从一个密钥将NSDictionary的许多对象存储到NSMutableArray但我不知道。

这是我的代码:

//NSArray * a = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"7",@"9", nil];
//NSArray *b = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"0", nil];
NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:a,@"number1",b,@"number2", nil];

NSMutableArray *array = [NSMutableArray alloc].... ?

我希望商店对象位于NSDictionary

NSMutableArray的number1键中

2 个答案:

答案 0 :(得分:1)

由于您似乎将数组存储为NSDictionary元素,因此您可以执行以下操作:

NSMutableArray *array = [[NSMutableArray alloc] initiWithArray:dic[@"number1"]];

NSMutableArray *array = [NSMutableArray arrayWithArray:dic[@"number1"]];

答案 1 :(得分:0)

将对象添加到NsDictionary数组中:

NSMutableDictionary * datos = [array objectAtIndex:i];
[datos setObject:@"hola" objectForKey@"newKey"];