-3

I have an array of objects. Each object has a key "username".

Is there a swift way of sorting this array of objects into ascending order?

(array(at: indexPath.row) as AnyObject).value(forKey: "username") as? String)!

Thanks

user2512523
  • 1,229
  • 2
  • 15
  • 25

1 Answers1

3
yourArray.sorted({ $0.username < $1.username})
Vlad Pulichev
  • 3,162
  • 2
  • 20
  • 34