My changes are not correctly written to persisted store.
Originally created by @markst on GitHub (Nov 20, 2018).
I'm using a `UnsafeDataTransaction` in combination with `ListMonitor` which I display results in progress prior to committing saved changes.
My `ListMonitor` does not update with results unless I call:
```swift
try? transaction.unsafeContext().save()
```
However upon attempting to persist my changes such as:
```swift
transaction?.commit({ [weak self] (error) in
if error == nil {
self?.navigationController?.popViewController(animated: true)
} else {
ErrorHandler.showError(with: error?.localizedDescription ?? "Error Occured...")
}
})
```
My changes are not correctly written to persisted store.
@markst commented on GitHub (Nov 20, 2018):
If I force saving on the parent context:
```swift
try? transaction?.unsafeContext().parent?.save()
```
The changes are correctly persisted.
How do you confirm that the changes are not persisted?
Do you get an error within the commit block?
@JohnEstropia commented on GitHub (Nov 20, 2018):
How do you confirm that the changes are not persisted?
Do you get an error within the `commit` block?
@markst commented on GitHub (Nov 20, 2018):
No error. I perform a fetch later on in the app's lifetime & no results are returned.
It appears due to `self.hasChanges` guard returning early & never breaking into saving the parent:
https://github.com/JohnEstropia/CoreStore/blob/40f458a09c0177d15ceab1561acaede2799c4f2d/Sources/NSManagedObjectContext%2BTransaction.swift#L186
@JohnEstropia
On further investigation it seems I should be using flush(). #71
This produces the desired effect with commit() correctly persisting to disk.
Is it all good to simply destroy the transaction if I changes should not be persisted?
@markst commented on GitHub (Nov 30, 2018):
@JohnEstropia
On further investigation it seems I should be using `flush()`. #71
This produces the desired effect with `commit()` correctly persisting to disk.
Is it all good to simply destroy the transaction if I changes should not be persisted?
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 @markst on GitHub (Nov 20, 2018).
I'm using a
UnsafeDataTransactionin combination withListMonitorwhich I display results in progress prior to committing saved changes.My
ListMonitordoes not update with results unless I call:However upon attempting to persist my changes such as:
My changes are not correctly written to persisted store.
@markst commented on GitHub (Nov 20, 2018):
If I force saving on the parent context:
The changes are correctly persisted.
@JohnEstropia commented on GitHub (Nov 20, 2018):
How do you confirm that the changes are not persisted?
Do you get an error within the
commitblock?@markst commented on GitHub (Nov 20, 2018):
No error. I perform a fetch later on in the app's lifetime & no results are returned.
It appears due to
self.hasChangesguard returning early & never breaking into saving the parent:https://github.com/JohnEstropia/CoreStore/blob/40f458a09c0177d15ceab1561acaede2799c4f2d/Sources/NSManagedObjectContext%2BTransaction.swift#L186
@markst commented on GitHub (Nov 30, 2018):
@JohnEstropia
On further investigation it seems I should be using
flush(). #71This produces the desired effect with
commit()correctly persisting to disk.Is it all good to simply destroy the transaction if I changes should not be persisted?
@JohnEstropia commented on GitHub (Nov 30, 2018):
@markst Yes, discarding the transaction will remove all unsaved changes.