NSSortDescriptors with Collections Operations

Suppose we need to sort objects based on the length of the array (property named transactions).
We can use NSSortDescriptors like that:

NSSortDescriptor *desc = [NSSortDescriptor sortDescriptorWithKey:@"transactions.@count" ascending:YES]; 
NSArray *descriptors = @[desc];
return [self.items sortedArrayUsingDescriptors:descriptors];

The general case for it is  Collections Operations:

NSNumber *numberOfTransactions = [transactions valueForKeyPath:@"@count"];

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s