mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Adding swiftier syntax for DataStack.perform methods #154
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 @sidmani on GitHub (Aug 7, 2017).
Based on the way Swift 3 reworked GCD's async methods, I think it would be convenient to add some syntactic sugar so that this:
can be written like this:
I've been using a simple extension that does this already:
I can write up a pull request if you like the idea (waiting on #182 though, since I'm working on the swift-4 branch).
@JohnEstropia commented on GitHub (Aug 8, 2017):
Thank you for the suggestion!
CoreStore's API design is leaned towards brevity more than convenience.
It was a conscious design to require either
completion:orsuccess:failure:arguments for async transactions as I don't want to encourage people to ignore errors. (This is also reflected byperform(synchronous:)being athrowsmethod). Doing so, writingcompletion: { _ in }can explicitly communicate that the error handing was intentionally (as opposed to accidentally) ignored.In principle, convenience at the cost of safety should be opt-out and is the developer's responsibility.
That said, of course you are free to use the helper methods such as yours in your own projects :)
(I have a couple in my own projects too)
@sidmani commented on GitHub (Aug 8, 2017):
Good point, in my situation transaction errors are safe to ignore but that's not necessarily the case.