I have the following code in my delegate deletion as a shortcut for working with CoreData in my other view controllers:
let ad = UIApplication.shared.delegate as! AppDelegate let context = ad.persistentContainer.viewContext
However, now I get the error message:
"UI API called from background thread" and "UIApplication.delegate should be used only from the main thread."
I am working with CoreData while my application is in the background, but this is the first time I have seen this error message. Does anyone know what is going on here?
Update: I tried moving this inside the appDelegate class itself and using the following code -
let dispatch = DispatchQueue.main.async { let ad = UIApplication.shared.delegate as! AppDelegate let context = ad.persistentContainer.viewContext }
Now I can no longer access declarations and context variables outside of AppDelegate . Is something missing?
source share