Whats the difference between these closures?
let closureA: () -> ()
and
let closureB: () -> Void
If you arrived here because you got an error such as Cannot convert value of type 'Void.Type' to specified type 'Void'
, then it might be useful to consider that:
()
can mean two things:
()
can be a type - the empty tuple type, which is the same as Void
.()
can be a value - an empty tuple, which is the same as Void()
.In my case I was looking to change ()
to Void
, but this caused the error mentioned above. Solving it would either mean just keeping it as ()
or using Void()
. The latter can be put in a global constant let void = Void()
and then you can just use void
. Whether this is a good practice / style, is up for debate.