I'm trying to sort an NSSet of NSManagedObjects. The value for one of the set item's "pubDate" property is nil. The following code throws an exception [NSManagedObject valueForUndefinedKey] when it is sorted. How can I get it to ignore the element without a value for that key?
NSSortDescriptor *sortNameDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"pubDate" ascending:NO] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObjects:sortNameDescriptor, nil];
return [[self.items allObjects] sortedArrayUsingDescriptors:sortDescriptors];