Help with sortWithSelector

ksuther

Registered
Anybody know how sortWithSelector from NSMutableArray works!? :confused:
I don't :( I'm trying to write a method that sorts a list of menu items by name and then adds them, but I don't know what the format of a method called by sortWithSelector should be in. Could anybody help me? :)
 
Well, I looked at the documentation (you meant to say <code>sortUsingSelector</code>, right?) and I can understand your confusion. You have to implement a method that compares an object (itself) to another object and return a result. The method should look something like this:

<code>- (NSComparisonResult)compare:(id)obj</code>

<code>NSComparisonResult</code> is an enum type and defines the constants <code>NSOrderedAscending</code>, <code>NSOrderedSame</code>, and <code>NSOrderedDescending</code>. I guess you could return an <code>int</code> instead if you wanted.

Is this at all helpful to you or did I misunderstand your question?

Cheers,
Johan
 
Back
Top