mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Realtime saving #389
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @paoloandrea on GitHub (Aug 6, 2022).
Hi, I am starting to integrate your excellent project into my app.
I am now facing a problem.
How do I save to the database synchronously?
I need realtime saving.
I need to replace this function
do {
try MY_OBJECT.managedObjectContext?.save()
} catch let error {
fatalError("Failure to save context: (error)")
}
I thank you in advance for your response.
Thank you
@JohnEstropia commented on GitHub (Aug 6, 2022):
I wouldn't recommend using synchronous transactions as they may cause deadlocks. But if you are confident about how you use it, CoreStore does expose a
DataStack.performSynchronous()method.@paoloandrea commented on GitHub (Dec 28, 2022):
Hi, this is the code I am using to save data without async.
Is the method correct?
try? DataStack.perform(
synchronous: { (transaction) in
guard let localDATA= try? transaction.fetchOne(From(),Where("self == %@", data.objectID )) else {
return
}
localDATA.data = value_for_data
},
waitForAllObservers: false
)
Alternatively how can I save data?
Can you give me an example please.
Thank you