swift第一讲

2020-04-09  本文已影响0人  奇怪的知识增加了

swift系列课程

编译流程

Swift code --> Swift AST -->Raw Swift IL -->Canonical Swift IL-->LLVM IR -->Assembly-->Executable

关于常量
var num = 10
num += 20
let age = num
print(age)


func getAge() -> Int {
    return 10
}
let theAge = getAge()
print(theAge)
关于标识符
func 🐂🌞() {
    print("666")
}
🐂🌞()


let 👽 = 124
var 👀 = 888

值类型(value type) 枚举 optional
值类型(value type) 结构体 bool ,int ,float,double,character,string,array,dictionary,set
引用类型(reference type)
//默认是double
let letFloat:Float = 30.0
let letDouble = 30.0
//布尔
let bool = true //false
//字符串
let string = "小马哥"
//字符(可存储ASCII字符,Unicode字符)
let character:Character = "🐶"
//整数
let intDecimal = 17 //十进制
let intBinary = 0b10001 //二进制
let intOctal = 0o21 //八进制
let intHexadecimal = 0x11//十六进制
//浮点型
let doubleDecimal = 125.0 //十进制,等价于1.25e2 = 1.25*10^2
let doubleDecimal = 0.0125 //1.25e-2 = 1.25*10^-2
let doubleHexadecimale12 = 0xFp2//十六进制,意味着15*2^2 
let doubleHexadecimal2 = 0xFp-2 //十六进制,15*2^-2
//数组
let array = [1,2,3,3]
//字典
let dic = ["age":18]

100_0000
0001243.456
1_000_000_000.909090
//整数转换(两个不同类型的数据相互运算要转换成同样的类型)
let int1:UInt16 = 2_000
let int2:Uint8 = 1
let int3 = int1 + UInt16(int2)

//整数,浮点型转换
let int = 3
let double = 0.2323
let pi = Double(int) + double
let intPi = Int(pi)//强转double到int
//字面量可以直接相加,因为数字字面量本身没有明确的类型
let result = 3 + 0.236728378


//元祖
let error = (404,"not found")
let (sta1,sta2) = error//把元祖赋值给元祖
print(sta1)
let (sta1,_)=error//只赋值第一个元素,下划线表示忽略
let abc = (statusCode:200,msg:"成功")
print(abc.statusCode)
上一篇下一篇

猜你喜欢

热点阅读