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.

6
  • 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? Commented Sep 3, 2015 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. Commented Sep 3, 2015 at 13:37
  • Can you please post your code. Commented Sep 3, 2015 at 13:52
  • Provide NSLog of _arrOfDoc Commented Sep 3, 2015 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 and specifying the name at the sort property. Commented Sep 3, 2015 at 13:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.