Function used to sort list contents in iOS