I'm currently trying to teach myself Objective-C and was playing with an exercise where I needed to sort an array.
I managed to populate it using the following code:
NSSortDescriptor * newSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:TRUE];
NSArray *sortDescriptors = [NSArray arrayWithObject:newSortDescriptor];
[self.theBookStore sortUsingDescriptors:sortDescriptors];
My question is what is really going on here. I do not quite understand what I did.
Line 1: I understand, here I created a new object with a descriptor. It has two parameters, the column that I want to sort, and that it goes back.
Line 2: This is the line that I am confused about. Why do we need an array of sort descriptors? When I read this code, I suspect that it creates an array with only one row, which is correct?
Line 3: I understand that this is a call to the sortUsingDescriptors method, but again, my confusion is why this function expects an array.
I read the documentation, but I'm really looking for a simple explanation.