How do I know when a particular transaction has completed?
I want to run a particular block of code after a transaction is complete. How can I do this?
I am performing writes in the following war -
do {
try realm.write({
realm.add(<some object>)
})
}
catch {}
Transactions are executed synchronously. So you can just perform the code right after you execute the transaction.
I would recommend to "force-try" as seen below to abort in case of an error if you don't provide any kind of error handling. Transactions fail recoverable if you run out of disk space. In most situations, you would expect in the code run after a transaction, that your data was persisted, which wouldn't apply in case of an error. Furthermore you don't see any errors in development if you keep the catch path completely empty.
try! realm.write {
realm.add(<some object>)
}
runMoreCode()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With