Sorting an Array in Objective-C

Sorting an array is pretty simple, thanks to many helper classes you can sort not only by key but also by attributes (if you have array of objects).
Consider such array:

To sort it alphabetically just use:

and you will get such result:

Now consider array of objects, lets say it will be class called Person with attributes like firstName and lastName, to get it sorted by f.e. lastName use:

Isn’t it simple? But wait, there is more to come.
In many cases you want multiple sorting, so lets say sort persons by last name, then by first name. Here we come:

Example result will be:

Pretty cool, huh?

Leave a Reply