: Playground-noun:a place where people can playimport uikit//initialize an array of integers var arr = [1, 3, 5, 7, 8, 10, 12, 2, 0, 11, 9] Sort, default is from small to large sort arr.sort ()//through closures, custom sort method Arr.sort ({(A:int, b:int), Bool in return a > B})//Initialize an array of strings Var a RR2 = ["AA", "B", "BB", "ABCD", "AABBCC", "CDEFG", "a", "C"]//sort, sort by string length, if the length is equal, compare two strings Arr2.sort ({string1:string, string2:string), Bool in let string1length = string1.characters.count let string2lenght = String2.characters.count if string1length! = string2lenght {//Length unequal return String1length < string2lenght< c5/>} else { //length equal return string1 < string2 }})
The following is a simple syntax for closing a packet :
{( parameter )- return type in function body }
Basic syntax for closures