Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime saving #456

Open
paoloandrea opened this issue Aug 6, 2022 · 2 comments
Open

Realtime saving #456

paoloandrea opened this issue Aug 6, 2022 · 2 comments

Comments

@paoloandrea
Copy link

paoloandrea commented 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
Copy link
Owner

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants