I have successfully sorted the data I have by my sort key lastName
, but I want to know how to sort by lastName
, and then by firstName
. He
NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:YES];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor1, sortDescriptor2, nil]];
Notice that you are passing an array of sort descriptors. Simply create another descriptor for firstname and create the array with both descriptors. They will be applied in the order of the array.