Swift: The Difference Between Void and ()
5 (1)

Click to rate this post!
[Total: 1 Average: 5]

Last Updated on March 13, 2022 by Deya Eldeen

Void is a data type that is common across a lot of programming languages, in Swift’s standard library, it’s simply an empty tuple, it’s used for for functions that return nothing, when defining a function, if you don’t specify a return type, you get a function that return Void, this is how it’s defined in standard library.

public typealias Void = ()

You use Void to declare the type of a function, method, or closure, Keep in mind 🤓
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().


Leave a Reply

Your email address will not be published.