Something like this (untested):
descriptor = [[[NSSortDescriptor alloc] initWithKey:@"status" ascending:YES selector:@selector(customStatusCompare:)] autorelease]; @interface NSNumber (CustomStatusCompare) - (NSComparisonResult)customStatusCompare:(NSNumber*)other; @end @implementation NSNumber (CustomStatusCompare) - (NSComparisonResult)customStatusCompare:(NSNumber*)other { NSAssert([other isKindOfClass:[NSNumber class]], @"Must be a number"); if ([self isEqual:other]) { return NSOrderedSame; } else if (... all your custom comparison logic here ...) } }
source share