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
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.
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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