• 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: Custom compare: for NSDate sort descriptor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom compare: for NSDate sort descriptor


  • Subject: Re: Custom compare: for NSDate sort descriptor
  • From: George Orthwein <email@hidden>
  • Date: Tue, 9 Oct 2007 10:46:22 -0400

Solved! But not with a category after all. :)

I first implemented a category but found that nil date values weren't being sent to my custom compare method at all! Quite a problem. I searched a bit and did find a thread where the poster had created a custom NSSortDescriptor subclass... he couldn't quite remember why he didn't use a custom compare method and I suspect it was because of these nil values.
http://www.cocoabuilder.com/archive/message/cocoa/2006/7/5/166885


Luckily the last post in the thread had another suggestion. Create a dummy key that filters out the nil values into NSNull objects that can be compared. Well I immediately found that my custom compare category only applied to NSDate and not NSNull. However, I had it together enough this morning to put 2 and 2 together into a more elegant solution:

- (id)sortableValueForDueDate
{
	id value = [self valueForKey:@"due_date"];
	if (value==nil)
		value = [NSDate distantFuture];
	return (value);
}

I let the normal compare: do its work, by replacing nil values with distantFuture (which is coming up as 1-1-4001 if you ever wondered).

Thanks to Keary Suska for keeping me moving and to the list archives as well. The solution ended up being simple, but why is the journey so difficult? :P

George

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Custom compare: for NSDate sort descriptor
      • From: George Orthwein <email@hidden>
    • Re: Custom compare: for NSDate sort descriptor
      • From: "Adam R. Maxwell" <email@hidden>
References: 
 >Re: Custom compare: for NSDate sort descriptor (From: Keary Suska <email@hidden>)

  • Prev by Date: Re: Where/when to #import
  • Next by Date: Re: Where/when to #import
  • Previous by thread: Re: Custom compare: for NSDate sort descriptor
  • Next by thread: Re: Custom compare: for NSDate sort descriptor
  • Index(es):
    • Date
    • Thread