Swift中的部分更新与旧版的区别

1.

函数中的外部变量名取消 “#”方式,仅能用直接命名方式

1 错误
2 func swift(#str :NSString){}
3 正确
4 func swift(str str :NSString){}

2.

UIButton 的声明区别

错误:
let button = UIButton.buttonWithType(UIButton.Custom) as UIButton
正确:
let button = UIButton(type: UIButtonType.System)

3.

Printable 协议更名为  CustomStringConvertible

4.

经典的do-while语句改名了,改为了repeat-while:

1 var i = 0
2 repeat {
3     i++
4     print(i)
5while i < 10

 

5.

在Swift1中,有'println()'和'print()'两个在控制台打印语句的方法,前者是换行打印,后者是连行打印。在Swift2中,'println()'已成为过去,取而代之的是他俩的结合体。

print("我要换行!")

原文地址:https://www.cnblogs.com/fcug/p/5305474.html