我为上下文添加了NSMergePolicyType,但是每次遇到冲突时,应用程序都会崩溃。
我向xcdatamodeld中的表添加了约束(带有“ id”)

这是我的情况:
lazy var managedObjectContext: NSManagedObjectContext? =
{
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
let coordinator = self.persistentStoreCoordinator
if coordinator == nil {
return nil
}
var managedObjectContext = NSManagedObjectContext(concurrencyType: NSManagedObjectContextConcurrencyType.privateQueueConcurrencyType)
managedObjectContext.persistentStoreCoordinator = coordinator
managedObjectContext.mergePolicy = NSMergePolicyType.overwriteMergePolicyType
return managedObjectContext
}()
Run Code Online (Sandbox Code Playgroud)
这是保存:
func saveContext(onSuccess: …Run Code Online (Sandbox Code Playgroud)