views:

57

answers:

1
//list has type of NSMutableArray

NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"date" ascending:YES] autorelease];
[list sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];

I got this exception: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSDate 0x5d57980> valueForUndefinedKey:]: this class is not key value coding-compliant for the key date.'

Any idea? How to fix it?

+1  A: 

An NSDate does not have the -date method, so your NSSortDescriptor won't work.

Why not just use

[list sortUsingSelector:@selector(compare:)];

?

KennyTM
Thank you! Actually first I thought I needed to define the compare:, but actually compare: was defined in the system, correct?
sza
@sza: [Yes](http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDate/compare:).
KennyTM