Re-arrange huge number of dictionaries based on group id
<p>I need to re-arrange below array of dictionaries:</p>

<pre><code>(
  {
   name : "aaa"
   group_id : 1.1
  },
  {
   name : "bbb"
   group_id : 1.2
  },
  {
   name : "ccc"
   group_id : 1.1
  },
  {
   name : "ddd"
   group_id : 1.2
  },
  {
   name : "aaa"
   group_id : 1.3
  },
  ...
)
</code></pre>

<p>TO this:</p>

<pre><code>(
  (
   {
    name : "aaa"
    group_id : 1.1
   },
   {
    name : "ccc"
    group_id : 1.1
   }
  ),
  (
   {
    name : "bbb"
    group_id : 1.2
   },
   {
    name : "ddd"
    group_id : 1.2
   }
  ),
  {
   name : "aaa"
   group_id : 1.3
  },
  ...
)
</code></pre>

<p>The array of dictionaries need to be re-arranged is of count more than 1500. Need to re-arrange this as fast as possible. </p>

<p>I am using this:</p>

<pre><code>-(NSMutableArray *)filterForAnnotationsWithArray:(NSMutableArray *)originalArray{

    NSMutableArray *requiredArr = [NSMutableArray array];
    NSMutableArray *indexesArr = [NSMutableArray array];
    NSMutableArray *tempRemovingIndexesArr = [NSMutableArray array];
    NSMutableArray *filteringArr1 = [NSMutableArray arrayWithArray:[removeNullValues removeNullinData:originalArray]];

    for (int i=0; i&lt;originalArray.count; i++) {
        [indexesArr removeAllObjects];
        for (NSDictionary *dict in filteringArr1) {
            if ([[dict valueForKey:@"group_id"] isEqualToString:[[originalArray objectAtIndex:i] valueForKey:@"group_id"]]) {
                if (![tempRemovingIndexesArr containsObject:[NSString stringWithFormat:@"%lu",(unsigned long)[filteringArr1 indexOfObject:dict]]]) {
                    [indexesArr addObject:[NSString stringWithFormat:@"%lu",(unsigned long)[filteringArr1 indexOfObject:dict]]];
                    [tempRemovingIndexesArr addObject:[NSString stringWithFormat:@"%lu",(unsigned long)[filteringArr1 indexOfObject:dict]]];
                }
            }
            if ([filteringArr1 indexOfObject:dict] == filteringArr1.count-1) {
                if (indexesArr.count&gt;1) {
                    NSMutableArray *searchedArr = [NSMutableArray array];
                    for (NSString *str in indexesArr) {
                        [searchedArr addObject:[originalArray objectAtIndex:str.intValue]];
                    }
                    [requiredArr addObject:searchedArr];
                }
                else if(indexesArr.count == 1){
                    [requiredArr addObject:[originalArray objectAtIndex:[[indexesArr objectAtIndex:0] intValue]]];
                }
            }
        }
    }
    return requiredArr;
}
</code></pre>

<p>Any help appreciated.
Thanks in advance.</p>