Swift學習3 執行緒

2021-09-24 02:17:45 字數 599 閱讀 4243

// 主佇列非同步

dispatchqueue.main.async

// dispatchqueue.global().async

// 序列佇列同步

let serialqueue = dispatchqueue(label: "squeue")

serialqueue.sync

// 序列佇列非同步

serialqueue.async

// 並行佇列非同步

let parallqueue = dispatchqueue(label: "pqueue", attributes: .concurrent)

parallqueue.async

序列同步

序列非同步

並行同步

無意義,無法體現並行

並行非同步

// 延遲執行

let delay = dispatchtime.now() + dispatchtimeinterval.seconds(5)

dispatchqueue.main.asyncafter(deadline: delay)

swift學習筆記3

任何程式都有順序分支迴圈三種控制語句,其中預設的是順序 分支語句 if 和 switch 迴圈語句 while do。while for for。in 跳轉語句 break continue fallthrough return if結構 表示式 if 條件表示式 if 條件表示式 else if ...

Swift學習筆記3 邏輯

1 if var i 10 if i 0 錯誤寫法 if i 複製 2 switch 2.1 乙個case可以判斷多個值,用 隔開 let somecharacter character e switch somecharacter 輸出 e is a vowel 複製 2.2 不存在隱式穿透 no...

執行緒學習3

有四個執行緒1 2 3 4。執行緒1的功能就是輸出1,執行緒2的功能就是輸出2,以此類推.現在有四個檔案abcd。初始都為空。現要讓四個檔案呈如下格式 a 1 2 3 4 1 2.b 2 3 4 1 2 3.c 3 4 1 2 3 4.d 4 1 2 3 4 1.請設計程式。include stda...