Sort array of objects into ascending order

2.6k Views Asked by At

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

1

There are 1 best solutions below

0
On
yourArray.sorted({ $0.username < $1.username})