• 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: Sorting objects on attributes of related objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting objects on attributes of related objects


  • Subject: Re: Sorting objects on attributes of related objects
  • From: Zak Burke <email@hidden>
  • Date: Thu, 14 Sep 2006 10:46:18 -0400

Matt Kime wrote on 9/13/06 12:38 PM:
> Does sortArrayUsingKeyOrderArray support sorting based on the
> attributes of a related object? Or do I need to make sense of
> NSComparator? (anyone know of any good examples?)

For the record, here is a simple NSComparator example that sorts Person
objects by their nameFirst property:

public static NSComparator nameFirstComparator()
{
    return (new NSComparator() {
        public int compare(Object o1, Object o2) {
            return ((Person)
o1).nameFirst().compareToIgnoreCase(((Person) o2).nameFirst());
        }
    });
}

If you wanted to sort by a related field (say you have Person <-> User
and User has a lastLogin field), you could use this:

public static NSComparator lastLoginComparator()
{
    return (new NSComparator() {
        public int compare(Object o1, Object o2) {
            return ((Person)
o1).user().lastLogin().compareToIgnoreCase(((Person)
o2).user().lastLogin());
        }
    });
}

Cheers,

zak.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Sorting objects on attributes of related objects (From: "Matt Kime" <email@hidden>)

  • Prev by Date: Re: Database connection error (MYSQL)
  • Next by Date: OT Question: Google ADs and WebObjects Apps
  • Previous by thread: Unable to find framework named "dwtm"
  • Next by thread: Re: Sorting objects on attributes of related objects
  • Index(es):
    • Date
    • Thread