Realtime saving #389

Open
opened 2025-12-29 15:30:46 +01:00 by adam · 2 comments
Owner

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

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
Author
Owner

@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.

@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.
Author
Owner

@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

@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<DATA>(),Where<DATA>("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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#389