swift基础1-变量

(1)变量与常量

(2)基本类型

(3)强制转换

(4)Bool类型

(5)元组

(6)可选值


//变量和常量

var str = "Hello, playground"
let maxNum = 888

//指定类型

var str1:String = "test"
var int1:Int = 1
var dou1:Double = 1.11
var flo1:Float = 1.111111111111

//强制转换

var dou2:Double = Double(int1) + dou1

//Bool类型

var bool1:Bool = true
bool1 = false
if bool1 {
    println("i am true")
} else {
    println("i am false")
}

//元组

var registionResult = (name:"姓名",age:24,sex:"女")
var connectionResult = ("404","Not Found!")
registionResult.age
registionResult.name
registionResult.sex

var registion:(name:String,age:Int,sex:String)
registion.name = "xxx"


//可选值

var a:Int?

a = 12

a = "12".toInt()

println("age is" + String(a!))


你可能感兴趣的:(swift,元组,强制转换,可选值,变量常量)