Originally created by @avaroam on GitHub (Jan 25, 2017).
Just thought I'd mention that the commit() method of SynchronousDataTransaction is not marked with @discardableResult, meaning it must currently be used like this:
_ = transaction.commit()
I'm not sure if this is intentional, but it seems like something that would often not be used, and in the read me it is used without _ =
Also, same is true of commitAndWait()
Originally created by @avaroam on GitHub (Jan 25, 2017).
Just thought I'd mention that the `commit()` method of `SynchronousDataTransaction` is not marked with `@discardableResult`, meaning it must currently be used like this:
```
_ = transaction.commit()
```
I'm not sure if this is intentional, but it seems like something that would often not be used, and in the read me it is used without `_ =`
Also, same is true of `commitAndWait()`
This was intentional because the result should generally be handled. Incidentally beginSynchronous() was made @discardableResult so that you can handle the result in one place. Maybe interchange the discardableResult attribute on those two methods?
@JohnEstropia commented on GitHub (Jan 26, 2017):
This was intentional because the result should generally be handled. Incidentally `beginSynchronous()` was made `@discardableResult` so that you can handle the result in one place. Maybe interchange the discardableResult attribute on those two methods?
That makes sense! Having no discardable result on commit() makes it consistent with async transactions. Just thought I'd mention it because it's written without _ = in the README.
Out of curiosity, what would be the usual way to handle the SaveResult? What would be a use case for hasChanges, and is it really worth checking the CoreStoreError for all transactions? What would be a suitable course of action if an error did occur?
@avaroam commented on GitHub (Jan 26, 2017):
That makes sense! Having no discardable result on `commit()` makes it consistent with async transactions. Just thought I'd mention it because it's written without `_ =` in the README.
Out of curiosity, what would be the usual way to handle the `SaveResult`? What would be a use case for `hasChanges`, and is it really worth checking the `CoreStoreError` for all transactions? What would be a suitable course of action if an error did occur?
Since transactions produce .success when there are no changes, the hasChanges is used when you need distinguish that case. This is useful in cases like data imports.
Of course it is up to you and your app if you need to handle these results or not. The syntax just makes it clear that you explicitly chose to do it.
@JohnEstropia commented on GitHub (Jan 27, 2017):
Since transactions produce `.success` when there are no changes, the `hasChanges` is used when you need distinguish that case. This is useful in cases like data imports.
Of course it is up to you and your app if you need to handle these results or not. The syntax just makes it clear that you explicitly chose to do it.
Nice. I've just been ignoring the result in most cases (if not all), but I can definitely see where it could be useful. Thanks for the insight!
@avaroam commented on GitHub (Jan 27, 2017):
Nice. I've just been ignoring the result in most cases (if not all), but I can definitely see where it could be useful. Thanks for the insight!
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 @avaroam on GitHub (Jan 25, 2017).
Just thought I'd mention that the
commit()method ofSynchronousDataTransactionis not marked with@discardableResult, meaning it must currently be used like this:I'm not sure if this is intentional, but it seems like something that would often not be used, and in the read me it is used without
_ =Also, same is true of
commitAndWait()@JohnEstropia commented on GitHub (Jan 26, 2017):
This was intentional because the result should generally be handled. Incidentally
beginSynchronous()was made@discardableResultso that you can handle the result in one place. Maybe interchange the discardableResult attribute on those two methods?@avaroam commented on GitHub (Jan 26, 2017):
That makes sense! Having no discardable result on
commit()makes it consistent with async transactions. Just thought I'd mention it because it's written without_ =in the README.Out of curiosity, what would be the usual way to handle the
SaveResult? What would be a use case forhasChanges, and is it really worth checking theCoreStoreErrorfor all transactions? What would be a suitable course of action if an error did occur?@JohnEstropia commented on GitHub (Jan 27, 2017):
Since transactions produce
.successwhen there are no changes, thehasChangesis used when you need distinguish that case. This is useful in cases like data imports.Of course it is up to you and your app if you need to handle these results or not. The syntax just makes it clear that you explicitly chose to do it.
@avaroam commented on GitHub (Jan 27, 2017):
Nice. I've just been ignoring the result in most cases (if not all), but I can definitely see where it could be useful. Thanks for the insight!