views:

119

answers:

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.

+2  A: 

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.

Zydeco
Yes, but how would I create the function or selector or whatever?
Jonathan
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.
Zydeco