I have recently been getting the error every time I run my app without fail: Thread 1: EXC_BAD_ACCESS (code=2, address=0x16ee77ff4)
func loadTrays(with request: NSFetchRequest<Tray> = Tray.fetchRequest()) {
do {
trayArray = try context.fetch(request)
trayArray = trayArray.reversed()
} catch {
print("Error fetching data from context: \(error)")
}
trayCollectionView.reloadData()
}
The line that is highlighted by the error is:
trayArray = try context.fetch(request)
I've spent hours looking through SO and Google for a solution but I haven't found one. I've also enabled Zombie objects in the Scheme but I don't get any output into the console. I realize that this error typically comes from pointers trying to access deallocated memory or that the pointer may be corrupt. Furthermore, if there are any resources that anyone can recommend to practice good memory management skills / concepts, please let me know. Additionally, I notice that in the debug navigator, the CPU usage is 99%. Not sure if this is related? I appreciate any help given.
Replying to Gigi's comment:
Persistent Container (AppDelegate):
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "Trayful_V2")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
}
})
return container
}()
I declare the context before "override init" in a class with subclass UIView that I am using as a popup:
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext