Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #0 0x00000001948b89bc in +[NSManagedObjectContext __Multithreading_Violation_AllThatIsLeftToUsIsHonor__] ()
- #1 0x0000000194853724 in -[_PFBatchFaultingArray managedObjectIDAtIndex:] ()
- #2 0x0000000194853600 in -[_PFMutableProxyArray newArrayFromObjectIDs] ()
- #3 0x0000000194853548 in -[_PFMutableProxyArray arrayFromObjectIDs] ()
- #4 0x0000000194852638 in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidSave:] ()
- #5 0x00000001924e622c in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
- #6 0x00000001924e5930 in _CFXRegistrationPost ()
- #7 0x00000001924e56ac in ___CFXNotificationPost_block_invoke ()
- #8 0x0000000192554b9c in -[_CFXNotificationRegistrar find:object:observer:enumerator:] ()
- #9 0x0000000192427bf4 in _CFXNotificationPost ()
- #10 0x0000000192f2e6bc in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
- #11 0x00000001948c5b48 in -[NSManagedObjectContext(_NSInternalNotificationHandling) _postContextDidSaveNotificationWithUserInfo:] ()
- #12 0x0000000194850350 in -[NSManagedObjectContext(_NSInternalAdditions) _didSaveChanges] ()
- #13 0x000000019483ca0c in -[NSManagedObjectContext save:] ()
- var initializationError: NSError?
- // The persistent container (local database) for the application.
- lazy var persistentContainer: NSPersistentContainer = {
- let container = NSPersistentContainer(name: self.storeName)
- container.loadPersistentStores(completionHandler: { (storeDescription, error) in
- if let error = error as NSError? {
- self.initializationError = error // This will be displayed by the AppDelegate
- }
- })
- return container
- }()
- // The managed object context for the main thread of the application.
- lazy var mainObjectContext: NSManagedObjectContext? = {
- // Get the main thread context.
- let context = self.persistentContainer.viewContext
- context.mergePolicy = NSOverwriteMergePolicy // In-memory properties overwrite datastore properties
- context.automaticallyMergesChangesFromParent = true // Merge all changes.
- return context
- }()
- // Return a managed object for background threads to create and modify objects without affecting the main thread until necessary.
- lazy var backgroundObjectContext: NSManagedObjectContext? = {
- // Get a background thread context.
- let context = self.persistentContainer.newBackgroundContext()
- context.mergePolicy = NSOverwriteMergePolicy // In-memory properties overwrite datastore properties
- context.automaticallyMergesChangesFromParent = true // Merge all changes.
- return context
- }()
- // Synchronously save any pending object changes in a managed object context to the database persistent store.
- class func saveAnyChangesSync(_ context: NSManagedObjectContext) -> NSError? {
- var error: NSError?
- // If the context has changes, save them.
- if context.hasChanges {
- do {
- try context.save()
- } catch let saveError as NSError {
- error = saveError
- NSLog("CoreData error saving context (saveError)")
- }
- }
- return error
- }
- // When initializing:
- persistentContainer.viewContext.automaticallyMergesChangesFromParent = true
- persistentContainer.viewContext.mergePolicy = NSMergePolicy.mergeByPropertyStoreTrump
- // And when saving:
- persistentContainer.performBackgroundTask { moc in
- moc.automaticallyMergesChangesFromParent = true
- moc.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
- autoreleasepool {
- // ... do some nsmanagedobject loading/changing
- }
- do {
- try moc.save()
- } catch {}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement