What is type '()' in swift? -
this question has answer here:
i'm receiving event passes parameter of type ()
.
is empty tuple..?
i'm referring type of expression:
let x = ()
()
both type (and void
type alias empty tuple type) , value of type. so
let x = ()
defines x
constant property of type ()
(aka void
) value ()
.
equivalent statements be
let x:() = () let x:void = ()
but not
let x = void // error: expected member name or constructor call after type name
because void
type not value.
when defining function types no parameters and/or no return value there seems consensus use ()
empty parameter list, , void
no return value. can example seen in uikit completion handlers, or execution blocks submitted gcd dispatch queues, e.g.
func sync(execute block: () -> void)
Comments
Post a Comment