Xcode 8.3, Swift 3.1 - Using common SQLite database as persistent container.
lazy var persistentContainer: NSPersistentContainer = { | |
let sqlitePath = Bundle.main.url(forResource: "DATABASE_NAME", withExtension: "sqlite") | |
if FileManager.default.fileExists(atPath: sqlitePath!.path) { | |
let container = NSPersistentContainer(name: "DATABASE_NAME") | |
let description = NSPersistentStoreDescription(url: sqlitePath!) | |
description.shouldInferMappingModelAutomatically = true | |
description.shouldMigrateStoreAutomatically = true | |
container.persistentStoreDescriptions = [description] | |
container.loadPersistentStores(completionHandler: { (storeDescription, error) in | |
if let error = error as NSError? { | |
fatalError("Unresolved error \(error), \(error.userInfo)") | |
} | |
}) | |
return container | |
} | |
let container = NSPersistentContainer(name: "DATABASE_NAME") | |
container.loadPersistentStores(completionHandler: { (storeDescription, error) in | |
if let error = error as NSError? { | |
fatalError("Unresolved error \(error), \(error.userInfo)") | |
} | |
}) | |
return container | |
}() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment