ios - Sort an array by ID and separate same ids in arrays -


i trying tackle following sorting , separating, have array ids 1,2,3,4,5,3,2,1.

sorting array nspredicate quite straightforward how can separate same ids in separate sub-arrays [[1,1][2,2,],[3,3],[4],[5]]? guess 1 option loop sorted array , compare previous index ids, wondering if helper function exist in ios, reading nsorderedset cant seem find if can help.

a combination of ordered , counted sets:

nsarray *array = @[@1,@2,@3,@4,@5,@3,@2,@1]; nsorderedset *os = [[nsorderedset alloc] initwitharray:array]; nscountedset *cs = [[nscountedset alloc] initwitharray:array]; nsmutablearray *sortedarray = [@[] mutablecopy];  [os enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop) {     nsmutablearray *countarray = [@[] mutablecopy];     (int = 0; < [cs countforobject:obj]; ++i) {         [countarray addobject:obj];     }     [sortedarray addobject:[countarray copy]]; }]; 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -