swift - Tuple member extraction in closure arguments -
considering array of tuple :
var tuplearray = [(string, int)]() tuplearray.append(("bonjour", 2)) tuplearray.append(("allo", 1)) tuplearray.sort { (t1 , t2) -> bool in let (_, n1) = t1 let (_, n2) = t2 return n1 < n2 } i make closure shorter doing :
tuplearray.sort { ((_, n1) , (_, n2)) -> bool in n1 < n2 } first: possible?
second: if possible syntaxe?
thanks
well, can use short closure syntax:
tuplearray.sort { $0.1 < $1.1 } see the official guide short closure syntax, .1 tuple index access.
Comments
Post a Comment