1

I have an NSArray of JSON file locations. There are stored in the user's/app's Document directory and inside each JSON file is a name value.

I'm able to retreive the data from JSON files, I don't need help with tht. But I need help on sorting NSArrays I have no idea how I can do that based on a value inside the file, while not being pathetically slow.

This is on the iPhone btw.

In sum how do I customly reorder NSArrays.

1 Answer 1

2

NSArray contents are immutable, but there are several methods for creating a sorted copy of the array, like sortedArrayUsingFunction:context:, sortedArrayUsingSelector: or sortedArrayUsingDescriptors:

Note that the new sorted array does not copy the elements of the original done, it just retains them.

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

2 Comments

Yes, but how would I create the function or selector or whatever?
The selector will be called on any object of the array, with one argument that is any other object, and must return NSOrderedAscending, NSOrderedSame or NSOrderedDescending. The function is the same, but it receives two objects and the context pointer, which you can use if you need to pass additional data to the comparison function.

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.