Swift_4 _ closure (Blocks)
Import Foundationprintln ("Hello, World! ") Var arr = [,] func hasClosure (list: [Int], v2: Int, cb :( num: Int, v3: Int)-> Bool) -> Bool {for item in arr {if (cb (num: item, v3: v2) {return true ;}return false ;}var v2 = hasClosure (arr, 82, {(num: Int, v3: Int)-> Bool in return num> = v3;}); println ("v2 is \ (v2 )") // The sort function sorts the values in an array of known types based on the sort closure you provide. Once sorting is completed, the function returns a new array of the same size as the original array, which contains the same type of elements that have been correctly sorted. let names = ["Chris", "Alex ", "Ewa", "Barry", "Daniella"] func backwards (s1: String, s2: String)-> Bool {return s1> s2} var reversed = sort (names, backwards) // reversed is equal to ["Ewa", "Daniella", "Chris", "Barry", "Alex"] // closure version reversed = sort (names, {(s1: String, s2: String)-> Bool in return s1> s2}) // single row reversed = sort (names, {(s1: String, s2: String) -> Bool in return s1> s2}) // reversed = sort (names, {s1, s2 in s1> s2}) // reversed = sort (names, {$0> $1}) // ultimate simplified reversed = sort (names,>) println ("reversed is \ (reversed )") // closure expression // {// (parameters)-> returnType in // statements //}