Swift-style-guide: Use () -> Void for closures with no parameters that return nothing

Created on 7 Feb 2017  路  3Comments  路  Source: raywenderlich/swift-style-guide

This seems to be the standard these days. () -> (), (Void) -> () are not preferred.

Most helpful comment

() -> Void is prefered

All 3 comments

() -> Void is prefered

I think this rule should follow from two other rules:

  1. Don't use (Void) as a closure input; just use ().
  2. Use Void instead of () for closure outputs.
    Especially with Swift 3's enforcement of parentheses for inputs, I think this adds clarity.

*I do think Void may be better as a tuple element than (). e.g.

let 茠: (Void, Int) -> Void = {_, int in}

let void: Void = 茠( (), 1 )
茠(void, 2)

I have never felt a desire to use something like this, but that doesn't mean it might not have a use, and it compiles. I like that signature better than this one:

let 茠: ( (), Int ) -> Void = {_, int in}

Added.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rayfix picture rayfix  路  3Comments

sima-11 picture sima-11  路  5Comments

rwenderlich picture rwenderlich  路  29Comments

Lweek picture Lweek  路  5Comments

jackwu95 picture jackwu95  路  6Comments