• 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: Chris Hanson <email@hidden>
  • Date: Sat, 16 Nov 2002 23:14:54 -0600

At 6:11 PM +0100 11/15/02, Lorenzo Puleo wrote:
Hi,
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?
Thank you.

Download my Open Source BDControl framework from <http://bdistributed.com/Projects/BDControl/>.

Then use the following to sort the mutable array "myArray":

BDSortOrdering *surnameOrdering;
NSArray *sortOrderings;

surnameOrdering = [BDSortOrdering sortOrderingWithKey:@"surname"
selector:BDCompareCaseInsensitiveAscending];

sortOrderings = [NSArray arrayWithObjects:surnameOrdering, nil];

[myArray sortUsingKeyOrderArray:sortOrderings];

If you want, you can sort by surname and then by name, by using this code:

BDSortOrdering *surnameOrdering;
BDSortOrdering *nameOrdering;
NSArray *sortOrderings;

surnameOrdering = [BDSortOrdering sortOrderingWithKey:@"surname"
selector:BDCompareCaseInsensitiveAscending];

surnameOrdering = [BDSortOrdering sortOrderingWithKey:@"name"
selector:BDCompareCaseInsensitiveAscending];

sortOrderings = [NSArray arrayWithObjects:surnameOrdering,
nameOrdering, nil];

[myArray sortUsingKeyOrderArray:sortOrderings];

(I assume that the attributes of the objects in your array are actually named "name" and "surname" so they'll work properly with Key-Value Coding.)

The documentation for the BDSortOrdering class is online at <http://bdistributed.com/projects/BDControl/Documentation/Classes/BDSortOrdering.html>.

The BDControl framework will make your life as a Cocoa developer easier, and it's available under a BSD-style license.

-- Chris

--
Chris Hanson | Email: email@hidden
bDistributed.com, Inc. | Phone: +1-847-372-3955
Making Business Distributed | Fax: +1-847-589-3738
http://bdistributed.com/ | Personal Email: email@hidden
_______________________________________________
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: Chris Hanson <email@hidden>
References: 
 >Sort Array (From: Lorenzo Puleo <email@hidden>)

  • Prev by Date: Re: Some realities
  • Next by Date: Re: Marketing your Cocoa App... Re: Jobs
  • Previous by thread: Re: Sort Array
  • Next by thread: Re: Sort Array
  • Index(es):
    • Date
    • Thread