我想NSMutableArray
根据两个对象属性订购包含对象,其中一个具有double
类型,第二个具有NSString
?
我尝试使用此方法,但出现异常:
NSString * LASTNAME = @"lastName";
NSString * GRADE = @"grade";
NSSortDescriptor *lastDescriptor =
[[NSSortDescriptor alloc]
initWithKey:LASTNAME
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)];
NSSortDescriptor *firstDescriptor =
[[NSSortDescriptor alloc]
initWithKey:GRADE
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
NSArray * descriptors =
[NSArray arrayWithObjects:lastDescriptor, firstDescriptor, nil];
NSArray * sortedArray =
[students sortedArrayUsingDescriptors:descriptors];
@interface Student : NSObject
{
NSString * firstName;
NSString * lastName;
double grade;
}