The Difference Between Void and () in Swift

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().

Jameel Shehadeh

Senior iOS Engineer @ Evolution | Building dars ???

3 年

Never thought about this it does make sense well explained

要查看或添加评论,请登录

Deya Eldeen Elkhawaldeh的更多文章

社区洞察

其他会员也浏览了