Xcode UIView.init(frame:) must be used from main thread only

前端 未结 3 1897
时光取名叫无心
时光取名叫无心 2020-12-28 13:31

I\'m trying to render some views in background thread to not affect the main thread. That was never a problem before Xcode 9.

DispatchQueue.global(qos: .back         


        
3条回答
  •  天命终不由人
    2020-12-28 13:39

    Xcode 9 has a new runtime Main Thread Checker that detects call to UIKit from a background thread and generate warnings.

    I know its meant to generate warnings and not crash the app, but you can try disabling Main Thread Checker for your test target.

    I tried this code in a sample project, the debugger paused at the issue (as it is supposed to), but the app didn't crash.

    override func viewDidLoad() {
        super.viewDidLoad()
    
        DispatchQueue.global().async {
            let v = UIView(frame: .zero)
        }
    }
    

提交回复
热议问题