I want to check that objects from array is same or not and if yes then i want to merge element. For that I have done this but I am getting error that :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object'
Array is:
(
(
hitesh,
121231,
Hitesh,
Patel,
3,
1,
0,
0,
TGB
),
(
hitesh,
121231,
Hitesh,
Patel,
3,
1,
0,
0,
"The Fern"
)
)
My Code is:
-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{
int id=0;
NSLog(@"Array is%@",ary);
NSMutableArray *temp;
for(int i=0;i<[ary count];i++){
temp=[ary objectAtIndex:i];
NSLog(@"string%@",[temp objectAtIndex:8]);
if(id==[[temp objectAtIndex:4] integerValue]){
NSLog(@"inside");
NSMutableArray *temp1=[[NSMutableArray alloc]init];
temp1=[MyAppDelegate.searchResultArray objectAtIndex:i-1];
NSLog(@"temp1%@",temp1);
NSString *tempStr=[[temp1 objectAtIndex:8] stringByAppendingString:[temp objectAtIndex:8]];
NSLog(@"%@",tempStr);
[temp1 replaceObjectAtIndex:8 withObject:tempStr];
[MyAppDelegate.searchResultArray replaceObjectAtIndex:i-1 withObject:temp1];
}
else{
id=[[temp objectAtIndex:4] integerValue];
NSLog(@"temp is%@ %d",temp,id);
[MyAppDelegate.searchResultArray addObject:temp];
}
}
NSLog(@"%@",MyAppDelegate.searchResultArray);
}
Another issue is that After Completing this process I want to navigate page. Thats why I have written this method:
-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{ }
and I am doing this:
[self compute:[root valueForKey:@"searchResult"] completion:^{
NSLog(@"after co");
[self.navigationController pushViewController:SearchResultVC animated:YES];
}];
Should I have to return anything from method?