From dac54bf50d0f9a17d788d420cfdd9ba5fa15d446 Mon Sep 17 00:00:00 2001 From: Juny0110 Date: Thu, 15 Dec 2022 03:12:25 +0900 Subject: [PATCH] :sparkles: #36 Add Persistence of AppDelegate --- ThrowAway/ThrowAway/AppDelegate.swift | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ThrowAway/ThrowAway/AppDelegate.swift b/ThrowAway/ThrowAway/AppDelegate.swift index fde78b3..68eee4b 100644 --- a/ThrowAway/ThrowAway/AppDelegate.swift +++ b/ThrowAway/ThrowAway/AppDelegate.swift @@ -6,12 +6,12 @@ // import UIKit +import CoreData @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. configureNavigationBar() return true } @@ -31,14 +31,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: UISceneSession Lifecycle func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { - // Called when a new scene session is being created. - // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { - // Called when the user discards a scene session. - // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. - // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } + + lazy var persistentContainer: NSPersistentContainer = { + let container = NSPersistentContainer(name: "ThrowAway") + container.loadPersistentStores(completionHandler: { (storeDescription, error) in + if let error = error as NSError? { + fatalError("Unresolved error \(error), \(error.userInfo)") + } + }) + return container + }() }