1

I have 4 values coming from json (name, ratings, reviews and Qualifications). I want to sort this data using name, reviews and qualifications one by one. But when I sort this data then remaining values are not changing in array.

Here is my code.

_arrOfDoc_name = [_arrOfDoc_name sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];

From comments:

I have to show four values on my screen which are coming from 4 different arrays. but when i sort one array then values of another arrays are not gng to sort and it displays wrong data on screen. how can i sort data of remaining arrays using its index path.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
Jayesh
  • 35
  • 4
  • 2
    You're going to have to provide a much more detailed description of the problem. Is the outer collection an NSArray? What is the structure inside that (Specifically and in detail)? You say "I have four values coming from JSON (name, ratings, reviews and Qualifications)." What does that mean? Do you have 4 different arrays, and you want to sort all 4 arrays into the same order? Are you saying you want to sort using a primary key of name, then a secondary key of review,s and then a tertiary key of qualifications? – Duncan C Sep 03 '15 at 13:30
  • I have to show four values on my screen which are coming from 4 different arrays. but when i sort one array then values of another arrays are not gng to sort and it displays wrong data on screen. how can i sort data of remaining arrays using its index path. – Jayesh Sep 03 '15 at 13:37
  • Can you please post your code. – Arpit B Parekh Sep 03 '15 at 13:52
  • Provide NSLog of _arrOfDoc – Arpit B Parekh Sep 03 '15 at 13:53
  • Seems like you have an array containing objects with properties `name`, `rating`, `reviews` and `qualifications` and you want to sort the objects. You can do that using an [`NSSortDescriptor`](http://stackoverflow.com/questions/7001597/sorting-nsmutablearray-by-objects-property/7001668#7001668) and specifying the `name` at the sort property. – Joe Sep 03 '15 at 13:58
  • _arrOfDoc_name = [_arrOfDoc_name sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; NSLog(@"arr Of new Degre %@",arrOfNewDegree); for (int i=0; i < _arrOfDoc_name.count; i++) { NSString *str = [_arrOfDoc_name objectAtIndex:i]; int indexOfSelectedName = [arrOfNewDocName indexOfObject:str]; [_arrOfDoc_Qualification removeObjectAtIndex:indexOfSelectedName]; [_arrOfDoc_Qualification insertObject:[arrOfDegre objectAtIndex:i] atIndex:indexOfSelectedName]; – Jayesh Sep 10 '15 at 09:59

1 Answers1

0

Ok, your comments explain what you're trying to do.

The best answer is to NOT use 4 different arrays. Restructure your data to have a single array that contains dictionaries. Then sort the array of dictionaries.

Failing that, you'll have to be clever. You might be able to create an array of indexes and sort that, or hand-write a sort routine that sorts all 4 arrays at once.

Duncan C
  • 128,072
  • 22
  • 173
  • 272