Skip to content
Liu Lantao edited this page Jun 12, 2014 · 5 revisions

Xcode6

设置为默认开发工具

如果有多个版本,使用xcode-select将Xcode6设置为默认开发工具

sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/

直接开启swift控制台(非playground)

xcrun swift

Swift

基础语法

常量与变量

声明常量:

let myConstant = 10

读作声明一个名为myConstant的常量,值为10

声明变量:

var myVariable = 0

读作声明一个名为myVariable的变量,初值为0

类型声明

在常量或变量名后增加一个分号':',一个空格' ',以及类型名。

var welcomeMessage: String

读作声明一个名为welcomeMessage的String类型变量

如果声明时即为常量或变量赋值,则不必须加类型声明,因为Swift可以推断出合适的类型。

UI

UIAlertView

let alert: UIAlertView = UIAlertView()
alert.title = "This a simple UIAlertView"
alert.message = "Press OK to continue"
alert.addButtonWithTitle("OK")
alert.show()
Clone this wiki locally