Functions can return n values, where n >= 0
If a function returns 0 values, it returns an empty tuple: ()
If a function returns more than one value, it returns a tuple.
If a function returns only a single value, is it also returning a tuple? Tuples that contain a single item are essentially interchangeable with an item of that type, so saything that a function returns Int could be essentially the same as saying that a function returns (Int).
So, is it correct to say that all functions return tuples?
Parentheses around a single type are valid grouping tokens, e.g. in `(1 + 2) + 3`. This is why `let x: (foo: Int) = 5` is not valid, and `let x: (Int) = 5; x.0` is also invalid. It is also why `let x = (5)` is inferred to be of type Int, rather than (Int). From The Swift Programming Language -> Language Reference -> Types:
If there is only one element inside the parentheses, the type is simply the type of that element. For example, the type of
(Int)
is Int
, not (Int)
. As a result, you can name a tuple element only when the tuple type has two or more elements.Generally speaking, the type system understands the notion of a single-element tuple only as an implementation detail in the parser, but it is not reflected in compiled code. E.g. the dynamicType of (Int) and Int is Int.Type, not (Int).Type. The reason you see (Int) in Xcode's quick help is because quick help relies on the parsed rather than compiled metadata to display types. You'll also see this happen in syntax error messages.