Create an NSComparator to do this. That gives you the full power of Java to do sorting. I usually make them a public inner class of the EO I am sorting. Then use the NSArray method sortedArrayUsingComparator or the NSMutableArray method sortUsingComparator to sort using an instance of your new NSComparator subclass.

A trivial example:

    /**
     * Compares Websites by the site ID.
     */
     static class SiteIDComparator extends NSComparator
     {

        /**
         * Compares Websites by the site ID.
         *
* @see com.webobjects.foundation.NSComparator#compare (java.lang.Object, java.lang.Object)
         */
public int compare(Object firstObject, Object secondObject) throws ComparisonException
        {
            if ((firstObject == null) || (secondObject == null))
            {
throw new NSComparator.ComparisonException("Can't compare null objects");
            }

            Website firstSite = (Website)firstObject;
            Website secondSite = (Website)secondObject;

return NSComparator.AscendingStringComparator.compare (firstSite.siteID(), secondSite.siteID());
        }

     }


Chuck


On Feb 17, 2006, at 11:08 AM, Miguel Arroz wrote:

Hi!

This is probably a simple question, but I'm not finding an answer... how can I sort objects in memory using my own criteria? The alphabetic ordering is not enough... :)

  Yours

Miguel Arroz

      "GUERRA E' PAZ
       LIBERDADE E' ESCRAVIDAO
       IGNORANCIA E' FORCA"       -- 1984

Miguel Arroz
http://www.ipragma.com



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/chill% 40global-village.net

This email sent to [EMAIL PROTECTED]

--
Coming in 2006 - an introduction to web applications using WebObjects and Xcode http://www.global-village.net/wointro

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems. http://www.global-village.net/products/practical_webobjects




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to archive@mail-archive.com

Reply via email to