• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Sort Array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sort Array


  • Subject: Re: Sort Array
  • From: Max Seelemann <email@hidden>
  • Date: Sat, 16 Nov 2002 12:58:30 +0100

I have a short list with "Name" and "Surname" fields.
I want to sort this list by "Surname".
How should I build the NSArray?
How should I use the NSArray methods?

At this point it is important to know how your Array is build.
The best would be if you use your own Data-Class. And there
you just need to implement one or two funcions like this one:

- (NSComparisonResult)compareByName:(myData *)other
{
return [[self name] compare: [other name]];
}

And then you sort the Array using this function:

myArray = [myArray sortedArrayUsingSelector: @selector(compareByName:)];

The idea of this is, to send a comare Message to every object in your Array and then sort it by the results.
E.g. if your Array has just NSString objects you can use this function:

myArray = [myArray sortedArrayUsingSelector: @selector(compare:)];

understand? HTH

cheers

MAX
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Sort Array
      • From: Ondra Cada <email@hidden>
References: 
 >Sort Array (From: Lorenzo Puleo <email@hidden>)

  • Prev by Date: Re: NSDictionary question
  • Next by Date: Re: Files and arrays
  • Previous by thread: Re: Sort Array
  • Next by thread: Re: Sort Array
  • Index(es):
    • Date
    • Thread