Modifications to the > layout engine must not be performed from a background thread after it has been accessed from the main thread

后端 未结 3 864
渐次进展
渐次进展 2020-12-15 16:52

I just downloaded iOS 13 for my iPhone and the new Xcode. I wanted to test my app for iOS 13, but when I try to run my app it will give me a error after a few seconds. Error

3条回答
  •  佛祖请我去吃肉
    2020-12-15 17:22

    You should wrap handling error by DispatchQueue.main.async{}

    func Download_ID() {
        let urlString = "https://www.instagram.com/\(self.username_String)/?__a=1"
        guard let url = URL(string: urlString) else { return }
        URLSession.shared.dataTask(with: url) { data, urlResponse, error in
            guard let data = data, error == nil, urlResponse != nil else {
                // Add DispatchQueue
                DispatchQueue.main.async {
                  print(error)
                }
                return
            }
            do
            {
                let decoder = JSONDecoder()
                let downloadedData_user = try decoder.decode(Website.self, from: data)
                // your logic
                DispatchQueue.main.async {
                   // update or reload table in here
                }
            } catch {
                // Add dispach_queue
                DispatchQueue.main.async {
                  print(error)
                }
            }
        }.resume()
    }
    

提交回复
热议问题