mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-11-01 00:43:58 +00:00
Adding CoreData save function
This commit is contained in:
parent
a26b62aa4c
commit
fcf7d97764
|
@ -21,7 +21,7 @@ struct PersistenceController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// MARK: - Constructor
|
||||||
init(inMemory: Bool = false) {
|
init(inMemory: Bool = false) {
|
||||||
container = NSPersistentCloudKitContainer(name: "DHBW_Service")
|
container = NSPersistentCloudKitContainer(name: "DHBW_Service")
|
||||||
if inMemory {
|
if inMemory {
|
||||||
|
@ -45,7 +45,21 @@ struct PersistenceController {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preview content
|
// MARK: - Core Data Saving support
|
||||||
|
|
||||||
|
public func save() {
|
||||||
|
if self.context.hasChanges {
|
||||||
|
do {
|
||||||
|
try self.context.save()
|
||||||
|
print("In CoreData.stack.save()")
|
||||||
|
} catch {
|
||||||
|
let nserror = error as NSError
|
||||||
|
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Preview content
|
||||||
static var preview: PersistenceController = {
|
static var preview: PersistenceController = {
|
||||||
let result = PersistenceController(inMemory: true)
|
let result = PersistenceController(inMemory: true)
|
||||||
let viewContext = result.container.viewContext
|
let viewContext = result.container.viewContext
|
||||||
|
|
Loading…
Reference in New Issue
Block a user