When working with CoreData, we need access to the shared store which is available via the AppDelegate. To obtain a reference to the AppDelegate we can get it by doing the following:
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate
else {
return
}
Why do we have to be so safe when downcasting to the Appdelegate? Can the downcast ever fail for some reason and if so, why?
I have looked around and can't find a reason as to why we write this code, and wanting to know why I write things will help!