mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Editing objects in UnsafeDataTransaction #104
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mrichtsfeld on GitHub (Nov 28, 2016).
I need to use
UnsafeDataTransactionfor editing in some views. I change values from the UI which get stored to the object within the transaction. However theUnsafeDataTransactionuses its own queue. When working with CoreData without CoreStore it is necessary to edit an object with the queue of itsNSManagedObjectContextvia:myObject.managedObjectContext?.performAndWait { // do your changes here }I haven't found anything to do that on the
UnsafeDataTransaction.Is it intended do be done viaperformAndWaiton the managed object's context, or directly on theUnsafeDataTransaction? If there is any implementation necessary to do this I can fork and do it. I only want to discuss the right way to do it.Btw. great framework, keep up the good work 👍
@JohnEstropia commented on GitHub (Nov 28, 2016):
The UnsafeDataTransaction inherits a queue from BaseDataTransaction, but it never uses it. Using UnsafeDataTransactions means you explicitly want to bypass CoreStore's queueing mechanism.
While I recommend you use AsynchronousDataTransactions or SynchronousDataTransactions instead, if you really need to go without queueing then you are free to edit objects directly (at your discretion) or use Core Data's standard
performmethods.@mrichtsfeld commented on GitHub (Nov 28, 2016):
Thanks for your quick answer and the clarification on the
performmethods.Regarding the AsynchronousDataTransactions or SynchronousDataTransactions I would also prefer using these, but in my case I pass an object to a view for editing within an UnsafeDataTransaction. As soon as editing is finished I save/commit it. Maybe there is something I missed, but as far as I understand this cannot we accomplished either by synchronous or asynchronous data transaction, right? The first one is anyway using the current thread to do the work and the second uses a background queue, but there is still no way to keep it open for a while and commit it at the end, right?
@JohnEstropia commented on GitHub (Nov 28, 2016):
I see, yes UnsafeDataTransaction is a good use for this. If so, as long as there is no other transactions working on the same data while the UnsafeDataTransaction is in use then there shouldn't be a need to worry about performBlock methods.
@mrichtsfeld commented on GitHub (Nov 28, 2016):
Great, thanks for you help and clarifications 👍