Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to perform Array Comparison & merging
    primarykey
    data
    text
    <p>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 :</p> <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray replaceObjectAtIndex:withObject:]: mutating method sent to immutable object'</p> <p>Array is:</p> <pre><code>( ( hitesh, 121231, Hitesh, Patel, 3, 1, 0, 0, TGB ), ( hitesh, 121231, Hitesh, Patel, 3, 1, 0, 0, "The Fern" ) ) </code></pre> <p>My Code is:</p> <pre><code>-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{ int id=0; NSLog(@"Array is%@",ary); NSMutableArray *temp; for(int i=0;i&lt;[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); } </code></pre> <p>Another issue is that After Completing this process I want to navigate page. Thats why I have written this method:</p> <pre><code>-(void)compute:(NSMutableArray *)ary completion:(void (^)(void))completion{ } </code></pre> <p>and I am doing this:</p> <pre><code>[self compute:[root valueForKey:@"searchResult"] completion:^{ NSLog(@"after co"); [self.navigationController pushViewController:SearchResultVC animated:YES]; }]; </code></pre> <p>Should I have to return anything from method?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload