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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to