Reputation: 51
i have one mutable array with some value , In this array i have add one dictionary on index no 3 with old value , i mean to say i have add one more value on index no 3 Here is my data **This is my mutable array **
( {
Amount = 40;
DisplayMessage = "Select at least 1 item and a maximum of 1";
DisplayOrder = 1;
IsMandatory = 1;
IsQtyEditable = 0;
},
{
Amount = 30;
DisplayMessage = "Select at least 1 item and a maximum of 1";
DisplayOrder = 1;
IsMandatory = 1;
IsQtyEditable = 0;
},
{
Amount = 10;
DisplayMessage = "Select at least 1 item and a maximum of 1";
DisplayOrder = 1;
IsMandatory = 1;
IsQtyEditable = 0;
}
)
on index no 3 i have add dictionary mytxt = 1; Like this (in last line i have add mytxt = 1; on index no 3 )
{
Amount = 10;
DisplayMessage = "Select at least 1 item and a maximum of 1";
DisplayOrder = 1;
IsMandatory = 1;
IsQtyEditable = 0;
mytxt = 1;
}
Here is my code i try this but is return a error
for (int i =0; i< ArrayGetParent.count; i++) {
if(i == 3 )
{
NSMutableDictionary *dictArray=[[NSMutableDictionary alloc]init];
[dictArray setValue:@"1" forKey:@"mytxt"];
NSLog(@"%@",dictArray);
[nishantArray insertObject:dictArray atIndex:i];
}
}
this is my error Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray insertObject:atIndex:]: mutating method sent to immutable object'
Please help me . please share your valuable knowledge .
Upvotes: 0
Views: 460
Reputation: 23407
Define array as :
NSMutableArray *ArrayGetParent = [[NSMutableArray alloc]init];
NOTE : You have only three object according to array and in your for loop you take i = 3
it is not possible.
Solution :
for (int i =0; i< ArrayGetParent.count; i++) {
if(i == 2)
{
[[ArrayGetParent objectAtIndex:i] setObject:@"1" forKey:@"mytxt"];
}
}
Adding data only last dictionary OUTPUT
Upvotes: 0
Reputation: 3013
nishantArray
is not mutable, check where you define it and change it
Upvotes: 0