Swift function with Void return type versus no return type

Alexey Savchenko picture Alexey Savchenko · Sep 6, 2016 · Viewed 7.9k times · Source

I'm struggling with understanding return values in Swift. Can you explain the difference between these?

func someFunc() -> Void {}
func someFunc() {}

Answer

ozgur picture ozgur · Sep 6, 2016

Simply, there is no difference. -> Void is just an explicit way of saying that the function returns no value.

From docs:

Functions without a defined return type return a special value of type Void. This is simply an empty tuple, in effect a tuple with zero elements, which can be written as ().

Thus, these three function declarations below are same:

func someFunc() {}
func someFunc() -> Void {}
func someFunc() -> () {}