Returning Void
Prefer the Void typealias to () for types. It reads better. It also better matches return conventions in the Objective-C world. While this is not a particularly compelling reason for selecting a Swift style, it’s not a meaningless one either. Apple is divided on whether a void function returns () or Void. The Swift Programming Language book refers to both -> () and -> Void. The standard library returns -> Void and -> Swift.Void.
Some time back, an old-style Dev Forums post[48] clarified Apple’s stance at that time:
FWIW, we’ve recently decided to standardize on () -> Void (generally, () for parameters and Void for return types) across all of our documentation.
-
Prefer Void for type names.
-
Prefer () for argument signatures and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access