Closed AndrewScherba closed 5 years ago
Hi @AndrewScherba,
As soon as you call the context's save method it should be available in the main thread.
func createUser() {
self.dataStack.performInNewBackgroundContext { backgroundContext in
let entity = NSEntityDescription.entityForName("User", inManagedObjectContext: backgroundContext)!
let object = NSManagedObject(entity: entity, insertIntoManagedObjectContext: backgroundContext)
object.setValue("Background", forKey: "name")
object.setValue(NSDate(), forKey: "createdDate")
try! backgroundContext.save()
// READY IN MAIN THREAD!
}
}
emm so all object is sync and ready to use in mains thread after save?? but what about merge and save main context?
There's an observer for the created background thread: https://github.com/SyncDB/DATAStack/blob/master/Source/DATAStack.swift#L241
So when you save the observer will be called and will merge things in the main thread. https://github.com/SyncDB/DATAStack/blob/master/Source/DATAStack.swift#L351-L361
Closing until someone else requests this feature.
It would be good to have this feature.
In your example where comment READY
is located - the updated object isn't updated in the main thread - only after a short while.
How I can know when data which was save in background is ready for use in main context (thread)?