Skip to content

Instantly share code, notes, and snippets.

@tokizuoh
Last active May 19, 2024 03:40
Show Gist options
  • Save tokizuoh/0c1c015d464d6f762728b3212c0b04a1 to your computer and use it in GitHub Desktop.
Save tokizuoh/0c1c015d464d6f762728b3212c0b04a1 to your computer and use it in GitHub Desktop.
import UIKit
class ViewModel {
func heavyCall() {
var count = 0
while count < 1_000_000_000 {
count += 1
}
print(Thread.isMainThread) // false
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Task.detached {
let viewModel = ViewModel()
viewModel.heavyCall()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment