xcode – Swift playground打印括号

前端之家收集整理的这篇文章主要介绍了xcode – Swift playground打印括号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Xcode 7.2,Swift 2.0:
下面的代码在调试区域中打印“15()”.我原以为它打印“15 1”.为什么要打印括号?

var n = 15
print(n,n /= 10)

解决方法

因为赋值运算符没有返回任何内容.
它仍然执行.

请参阅此处的文档:Swift Docs

The assignment operator (=) does not return a value,to prevent it from being mistakenly used when the equal to operator (==) is intended.

猜你在找的Xcode相关文章