Sorting objects in Objective-C in Alphabet Order by Name

No comments on Sorting objects in Objective-C in Alphabet Order by Name

Written by

in

It is a very easy but a common task. There is no need to create any custom NSSortDescriptors. Let’s say, we have an unsorted array of RRRegion objects, that have a name property. This is how we can sort this array:

  NSArray *regionArray = [[RRSession sharedSession] regions];
  // Sorting in alphabet order by name
  NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
  regionArray = [regionArray sortedArrayUsingDescriptors:@[sortDescriptor]];

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *