Swift操场打印括号

Vin*_*van 3 xcode swift

Xcode 7.2,Swift 2.0:下面的代码在调试区域中打印"15()".我原以为它打印"15 1".为什么要打印括号?

var n = 15
print(n, n /= 10)
Run Code Online (Sandbox Code Playgroud)

Cri*_*tik 5

那是因为n /= 15表达式返回a Void,因为/=运算符Void在Swift中返回.我们可以从它的声明中看到:

public func /=<T : _IntegerArithmeticType>(inout lhs: T, rhs: T)
Run Code Online (Sandbox Code Playgroud)

因为在Swift中,Void是空元组的别名:

/// The empty tuple type.
///
/// This is the default return type of functions for which no explicit
/// return type is specified.
public typealias Void = ()
Run Code Online (Sandbox Code Playgroud)

传递给的第二个参数/表达式print被打印为().