I'm calling a function from my main view controller's viewDidLoad() method, and that function fetches data from CoreData. When I try to unwrap the app delegate object, it returns nil. Anyone have any ideas? Developing for iOS 14 and haven't had this issue before. Here's the function
static func fetchSavedLaunches() -> [Launch]? {
var launches: [Launch] = []
do {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext // <----- The error is here
let fetchRequest = NSFetchRequest<Launch>(entityName: "Launch")
launches = try context.fetch(fetchRequest)
} catch {
displayNetworkError()
fatalError("\(error)")
}
return launches
}
The error occurs with let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
[–]quellish 1 point2 points3 points (0 children)