【问题标题】:Deadlock not created when call performBlockAndWait on Main MOC from Main Thread从主线程调用主 MOC 上的 performBlockAndWait 时未创建死锁
【发布时间】:2019-08-28 10:56:03
【问题描述】:

覆盖 func viewDidLoad() { super.viewDidLoad()

    if let appDelegateObj = UIApplication.shared.delegate as? AppDelegate{
        print("Before \(Thread.current)")

        appDelegateObj.persistentContainer.viewContext.performAndWait {
            print("I am here \(Thread.current)")
        }

        print("After")
    }

}

【问题讨论】:

    标签: ios core-data


    【解决方案1】:

    performAndWait 首先检查它在哪个线程上。如果它调用预期的线程(在本例中为主线程),它只会执行该块。

    【讨论】:

      猜你喜欢
      • 2012-09-12
      • 2013-04-28
      • 2016-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-02
      相关资源
      最近更新 更多