Thursday, June 5, 2014

Sorting in Swift - elegant

let names = ["Chris", "Alex", "Ewa", "Barry", "Daniella"]

reversed = sort(names, { (s1: String, s2: String) -> Bool in
    return s1 > s2
    })

reversed = sort(names, { (s1: String, s2: String) -> Bool in return s1 > s2 } )

reversed = sort(names, { s1, s2 in return s1 > s2 } )

reversed = sort(names, { s1, s2 in s1 > s2 } )

reversed = sort(names, { $0 > $1 } )

reversed = sort(names, >)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.