JohnEstropia / CoreStore

Unleashing the real power of Core Data with the elegance and safety of Swift
MIT License
4k stars 254 forks source link

Realtime saving #456

Open paoloandrea opened 2 years ago

paoloandrea commented 2 years ago

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 2 years ago

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 1 year ago

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_fordata }, waitForAllObservers: false )

Alternatively how can I save data? Can you give me an example please. Thank you