SHARE
TWEET

Untitled

a guest Jul 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #0  0x00000001948b89bc in +[NSManagedObjectContext __Multithreading_Violation_AllThatIsLeftToUsIsHonor__] ()
  2. #1  0x0000000194853724 in -[_PFBatchFaultingArray managedObjectIDAtIndex:] ()
  3. #2  0x0000000194853600 in -[_PFMutableProxyArray newArrayFromObjectIDs] ()
  4. #3  0x0000000194853548 in -[_PFMutableProxyArray arrayFromObjectIDs] ()
  5. #4  0x0000000194852638 in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidSave:] ()
  6. #5  0x00000001924e622c in __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ ()
  7. #6  0x00000001924e5930 in _CFXRegistrationPost ()
  8. #7  0x00000001924e56ac in ___CFXNotificationPost_block_invoke ()
  9. #8  0x0000000192554b9c in -[_CFXNotificationRegistrar find:object:observer:enumerator:] ()
  10. #9  0x0000000192427bf4 in _CFXNotificationPost ()
  11. #10 0x0000000192f2e6bc in -[NSNotificationCenter postNotificationName:object:userInfo:] ()
  12. #11 0x00000001948c5b48 in -[NSManagedObjectContext(_NSInternalNotificationHandling) _postContextDidSaveNotificationWithUserInfo:] ()
  13. #12 0x0000000194850350 in -[NSManagedObjectContext(_NSInternalAdditions) _didSaveChanges] ()
  14. #13 0x000000019483ca0c in -[NSManagedObjectContext save:] ()
  15.      
  16. var initializationError: NSError?
  17.  
  18. // The persistent container (local database) for the application.
  19. lazy var persistentContainer: NSPersistentContainer = {
  20.  
  21.     let container = NSPersistentContainer(name: self.storeName)
  22.     container.loadPersistentStores(completionHandler: { (storeDescription, error) in
  23.         if let error = error as NSError? {
  24.             self.initializationError = error // This will be displayed by the AppDelegate
  25.         }
  26.     })
  27.     return container
  28. }()
  29.  
  30. // The managed object context for the main thread of the application.
  31. lazy var mainObjectContext: NSManagedObjectContext? = {
  32.  
  33.     // Get the main thread context.
  34.     let context = self.persistentContainer.viewContext
  35.     context.mergePolicy = NSOverwriteMergePolicy // In-memory properties overwrite datastore properties
  36.     context.automaticallyMergesChangesFromParent = true // Merge all changes.
  37.  
  38.     return context
  39. }()
  40.  
  41. // Return a managed object for background threads to create and modify objects without affecting the main thread until necessary.
  42. lazy var backgroundObjectContext: NSManagedObjectContext? = {
  43.  
  44.     // Get a background thread context.
  45.     let context = self.persistentContainer.newBackgroundContext()
  46.     context.mergePolicy = NSOverwriteMergePolicy // In-memory properties overwrite datastore properties
  47.     context.automaticallyMergesChangesFromParent = true // Merge all changes.
  48.  
  49.     return context
  50.  
  51. }()
  52.  
  53. // Synchronously save any pending object changes in a managed object context to the database persistent store.
  54. class func saveAnyChangesSync(_ context: NSManagedObjectContext) -> NSError? {
  55.  
  56.     var error: NSError?
  57.  
  58.     // If the context has changes, save them.
  59.     if context.hasChanges {
  60.  
  61.         do {
  62.             try context.save()
  63.  
  64.         } catch let saveError as NSError {
  65.             error = saveError
  66.             NSLog("CoreData error saving context (saveError)")
  67.         }
  68.     }
  69.     return error
  70. }
  71.      
  72. // When initializing:
  73. persistentContainer.viewContext.automaticallyMergesChangesFromParent = true
  74.  persistentContainer.viewContext.mergePolicy = NSMergePolicy.mergeByPropertyStoreTrump
  75. // And when saving:
  76. persistentContainer.performBackgroundTask { moc in
  77.     moc.automaticallyMergesChangesFromParent = true
  78.     moc.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump
  79.     autoreleasepool {
  80.         // ... do some nsmanagedobject loading/changing
  81.     }
  82.     do {
  83.         try moc.save()
  84.     } catch {}
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top