0

I am getting this error when I try to delete a saved file on my App. A bit of background of my app is that you create a game within the game. You enter your game name and game description and click save. After that, the screen takes you to activities and you create your tasks. The game name is also saved into a scene I created called load game. When I delete the game from load, the game crashes and I get that error. When I try to delete a task that I created in the game, it also crashes the game and I get that error. I made the relationship where the game has many tasks but the tasks can only have 1 game. Delete rule is cascade for both of them. Here is my Code.

import UIKit
import CoreData

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        return true
    }

    func applicationWillTerminate(_ application: UIApplication) {
        self.saveContext()
    }

    // MARK: - Core Data stack

    lazy var persistentContainer: NSPersistentContainer = {
        let container = NSPersistentContainer(name: "Gamification2")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        return container
    }()

    // MARK: - Core Data Saving support

    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                let nserror = error as NSError
                fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
            }
        }
    }
}

The eror shows up on the fatalError("Unresolved error (nserror), (nserror.userInfo)") line.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

0 Answers0