• 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 descriptor optimization
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sort descriptor optimization


  • Subject: Re: sort descriptor optimization
  • From: James Bucanek <email@hidden>
  • Date: Wed, 5 Jul 2006 07:23:13 -0700

Adam R. Maxwell wrote on Tuesday, July 4, 2006:

>We considered that.  However, our users want nil values and empty
>strings to sort last in an a-z ordered list, instead of first, for
>all objects.  Implementing this in NSSortDescriptor was also less
>code, and doesn't require adding a special category on every object
>that we sort.
>
>> As for some of your comparands being nil values, the obvious
>> suggestion is,
>> Don't Do That. m.
>
>Thanks, but that is not an option.  We need valueForKey: to return
>nil when there is no value for that key.

Apologies for jumping into this thread late, but I usually solve these kinds of problems by creating another method on the object just for sorting, such as

    - (id)sortableaValueForKey:(NSString*)key
    {
        id value = [self valueForKey:key];
        if (value==nil)
            value = [NSNull or whatever];
        return (value);
    }

You can continue to use valueForKey: programmatically the way you do now, but when you sort specify sortableValueForKey: as the property to sort on.

I have several data models for tables that return NSImages for some cells (indicating the status of the record in the table) via the method -(NSImage*)statusImage. Obviously, this is not suitable for sorting, so I create another property (-(int)sortableStatus) that returns a numeric value for each possible status condtion.

Create this as a category if you want to keep your model/view/sorting code separate from the implementation of your object.

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

This email sent to email@hidden

References: 
 >Re: sort descriptor optimization (From: "Adam R. Maxwell" <email@hidden>)

  • Prev by Date: Re: Permissions in an app bundle
  • Next by Date: Re: Permissions in an app bundle
  • Previous by thread: Re: sort descriptor optimization
  • Next by thread: Re: working with NSDecimalNumber and NSNumber
  • Index(es):
    • Date
    • Thread