import UIKit
import CoreData
@UIApplicationMain
class AppDelegate : UIResponder , UIApplicationDelegate {
var window: UIWindow ?
func application(_ application: UIApplication ,
didFinishLaunchingWithOptions
launchOptions: [ UIApplicationLaunchOptionsKey : Any ]?) -> Bool {
return true
}
func applicationWillResignActive(_ application: UIApplication ) {
}
func applicationDidEnterBackground(_ application: UIApplication ) {
}
func applicationWillEnterForeground(_ application: UIApplication ) {
}
func applicationDidBecomeActive(_ application: UIApplication ) {
}
func applicationWillTerminate(_ application: UIApplication ) {
}
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer (name: "hangge_1841" )
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)" )
}
}
}
}
|
请发表评论