Skip to content

Commit 8766aed

Browse files
author
Dilip Parmar
committed
Exluded core data files from backup (Default)
1 parent c236f7c commit 8766aed

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Sources/CoreDataWrapper/CoreDataWrapper.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ final public class CoreDataWrapper {
106106
// MARK: Set configuration to context
107107
@available(iOS 12.0, macOS 10.13, *)
108108
private func setConfigTo(context: NSManagedObjectContext) {
109-
context.mergePolicy = self.mergePolicy
110-
context.automaticallyMergesChangesFromParent = true
111-
context.shouldDeleteInaccessibleFaults = true
112-
context.retainsRegisteredObjects = false
109+
if context.hasChanges == false {
110+
context.mergePolicy = self.mergePolicy
111+
context.automaticallyMergesChangesFromParent = true
112+
context.shouldDeleteInaccessibleFaults = true
113+
context.retainsRegisteredObjects = false
114+
}
113115
}
114116

115117
// MARK: Persistent store coordinator
@@ -156,6 +158,13 @@ final public class CoreDataWrapper {
156158
case .inMemory:
157159
break
158160
}
161+
do {
162+
var resourceValues: URLResourceValues = URLResourceValues.init()
163+
resourceValues.isExcludedFromBackup = true
164+
try storeDescription.url?.setResourceValues(resourceValues)
165+
} catch let error {
166+
print("could not exlcude core data file from backup")
167+
}
159168
storeDescription.type = storeType.getStorageType()
160169
storeDescription.shouldMigrateStoreAutomatically = true
161170
storeDescription.shouldInferMappingModelAutomatically = true

0 commit comments

Comments
 (0)