You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
//
|
|
// CoreDataManager.swift
|
|
// elpha-ios
|
|
//
|
|
// Created by Dwayne Harris on 9/28/18.
|
|
// Copyright © 2018 Elpha. All rights reserved.
|
|
//
|
|
|
|
import CoreData
|
|
import Foundation
|
|
|
|
public class CoreDataManager {
|
|
static let shared = CoreDataManager()
|
|
|
|
lazy var persistentContainer: NSPersistentContainer = {
|
|
let container = NSPersistentContainer(name: "Elpha")
|
|
|
|
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
|
|
if let error = error as NSError? {
|
|
fatalError("Unresolved error \(error), \(error.userInfo)")
|
|
}
|
|
})
|
|
|
|
return container
|
|
}()
|
|
|
|
var context: NSManagedObjectContext {
|
|
get {
|
|
return persistentContainer.viewContext
|
|
}
|
|
}
|
|
|
|
func saveContext() {
|
|
if context.hasChanges {
|
|
do {
|
|
try context.save()
|
|
} catch {
|
|
let nserror = error as NSError
|
|
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
|
|
}
|
|
}
|
|
}
|
|
}
|