Ios 如何将NSMutableDictionary对象添加到位于last+;1.

Ios 如何将NSMutableDictionary对象添加到位于last+;1.,ios,nsmutabledictionary,Ios,Nsmutabledictionary,我有一个NSArray,其中NSMutableDictionary对象位于该数组中,如下所示。我想在该数组的索引2处获取一个对象,并将该NSMutableDictionary对象从以下数组添加到其他NSMutableDictionary中,该对象在位置6处已具有五个元素: ( { eventId=2; eventName=“Sweels”; }, { eventId=1; eventName=“Lakenge”; }, { eventId=23; eventName=“Royta”; } )

我有一个NSArray,其中NSMutableDictionary对象位于该数组中,如下所示。我想在该数组的索引2处获取一个对象,并将该NSMutableDictionary对象从以下数组添加到其他NSMutableDictionary中,该对象在位置6处已具有五个元素:

(
{
eventId=2;
eventName=“Sweels”;
},
{
eventId=1;
eventName=“Lakenge”;
},
{
eventId=23;
eventName=“Royta”;
}
)
我能够获得NSMutableDictionary对象,可以提取键和值,然后可以添加,但希望添加整个对象,而不提取键和值

{
    eventId = 23;
    eventName = "Royta";
}

可以使用此初始值设定项,使用另一个给定字典中包含的键和值初始化NSMutableDictionary对象:

- (instancetype)initWithDictionary:(NSDictionary *)otherDictionary
例如:

NSMutableDictionary *newDict = [[NSMutableDictionary alloc] initWithDictionary:extractedDict];
[newDict setValuesForKeysWithDictionary:extractedDict];
如果不想创建新的NSMutableDictionary对象,只需要向现有对象添加键/值,请使用以下方法:

- (void)setValuesForKeysWithDictionary:(NSDictionary *)keyedValues
例如:

NSMutableDictionary *newDict = [[NSMutableDictionary alloc] initWithDictionary:extractedDict];
[newDict setValuesForKeysWithDictionary:extractedDict];

如果希望所有值都作为单个对象,则必须这样做-

NSMutableArray *myArray = [[NSMutableArray alloc] init];

[myArray addObjectsFromArray:[paramsDictionary allValues]];

NSLog(@"%@",[paramsDictionary allValues]);

字典是没有顺序的——仅仅使用字典是不可能做到这一点的。您需要同时使用两种结构-字典和数组(可能是通过封装在自定义ordereddictionary类中)。