0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

swiftのスレッドを擬人化

Posted at

間違いあれば指摘していただけると助かります。

例えば

print("A")

DispatchQueue.global().async {
    // 重い処理
    let result = heavyCalculation()

    DispatchQueue.main.async {
        // 結果をUIに反映
        updateLabel(with: result)
    }
}

print("C")

会話

  1. メインさん:「Aって表示しとくで〜」
  2. バックグラウンドさん:「重い計算?おう、まかせといてや!終わったらメインさんに言うわ」
  3. メインさん:「Cもとりあえず表示しとこか〜」

(数秒後)

4. バックグラウンドさん:「終わったで!メインさん、表示頼むわ!」
5. メインさん:「おっしゃ、ラベル更新しとくわ!」

非同期処理と同期処理

同期:前の処理が終わるまで待つ
非同期:全ての処理が終わってから実行

名称未設定ファイル.drawio.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?