let與var

賦值

var v = 10
let l = 20

基本類型

let aInt: Int = 10
let aFloat: Float = 10.0
let aDouble: Double = 10.0
let aBool: Bool = true
let aString: String = "a"
let aWrapString:String = """
    白日依山盡,
    黃河入海流。
"""
let aChar: Character = "a"
// 元組1
let tuple = (1, "json", "success")
tuple.0
tuple.1
tuple.2
// 元組2
let tuple = (index: 1, type: "json", message: "success")
tuple.index
tuple.type
tuple.message

可選

let aLabel: UILabel? = UILabel()
let bLabel = aLabel!
print(type(of: bLabel))

let aLabel: UILabel? = nil

if let label = aLabel {
    print(type(of: label))
} else {

}

print(aLabel?.text?.count)
發佈了62 篇原創文章 · 獲贊 4 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章