|
| 1 | + |
| 2 | +import UIKit |
| 3 | +import CoreData |
| 4 | + |
| 5 | +@main |
| 6 | +class AppDelegate: UIResponder, UIApplicationDelegate { |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { |
| 11 | + // Override point for customization after application launch. |
| 12 | + return true |
| 13 | + } |
| 14 | + |
| 15 | + // MARK: UISceneSession Lifecycle |
| 16 | + |
| 17 | + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { |
| 18 | + // Called when a new scene session is being created. |
| 19 | + // Use this method to select a configuration to create the new scene with. |
| 20 | + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) |
| 21 | + } |
| 22 | + |
| 23 | + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { |
| 24 | + // Called when the user discards a scene session. |
| 25 | + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. |
| 26 | + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. |
| 27 | + } |
| 28 | + |
| 29 | + // MARK: - Core Data stack |
| 30 | + |
| 31 | + lazy var persistentContainer: NSPersistentContainer = { |
| 32 | + /* |
| 33 | + The persistent container for the application. This implementation |
| 34 | + creates and returns a container, having loaded the store for the |
| 35 | + application to it. This property is optional since there are legitimate |
| 36 | + error conditions that could cause the creation of the store to fail. |
| 37 | + */ |
| 38 | + let container = NSPersistentContainer(name: "FaceRecognition") |
| 39 | + container.loadPersistentStores(completionHandler: { (storeDescription, error) in |
| 40 | + if let error = error as NSError? { |
| 41 | + // Replace this implementation with code to handle the error appropriately. |
| 42 | + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. |
| 43 | + |
| 44 | + /* |
| 45 | + Typical reasons for an error here include: |
| 46 | + * The parent directory does not exist, cannot be created, or disallows writing. |
| 47 | + * The persistent store is not accessible, due to permissions or data protection when the device is locked. |
| 48 | + * The device is out of space. |
| 49 | + * The store could not be migrated to the current model version. |
| 50 | + Check the error message to determine what the actual problem was. |
| 51 | + */ |
| 52 | + fatalError("Unresolved error \(error), \(error.userInfo)") |
| 53 | + } |
| 54 | + }) |
| 55 | + return container |
| 56 | + }() |
| 57 | + |
| 58 | + // MARK: - Core Data Saving support |
| 59 | + |
| 60 | + func saveContext () { |
| 61 | + let context = persistentContainer.viewContext |
| 62 | + if context.hasChanges { |
| 63 | + do { |
| 64 | + try context.save() |
| 65 | + } catch { |
| 66 | + // Replace this implementation with code to handle the error appropriately. |
| 67 | + // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. |
| 68 | + let nserror = error as NSError |
| 69 | + fatalError("Unresolved error \(nserror), \(nserror.userInfo)") |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | +} |
| 75 | + |
0 commit comments