Thripthi Haridas Thripthi Haridas - 1 year ago 95
Swift Question

Swift Sorting Array<Array<AnyObject>>

I have the below response. how to sort according to the first element. i.e.

[["Albania", "AE"], ["United States", "US"]]

"United States",

Answer Source

One easy way to achieve this using Closures.

Here is a Shorthand way of sorting.

    let array = [["United States","US"],["Albania", "AE"],["India", "IN"],["United Kingdom", "UK"]]

    let arrAscending = array.sort({($0[0]) < ($1[0])})
    let arrDescending = array.sort({($0[0]) > ($1[0])})

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download