'catch' is now a reserved keyword in Swift 2.0, making it invalid for use as a method name
Propose renaming to "failed" or something similar.
Can I confirm you tested this?
I have not yet tested this yet, however the new reference is available at https://itunes.apple.com/us/book/swift-programming-language/id1002622538?mt=11.
In this reference, "catch" has been added as a reserved keyword (look in the section 'Lexical Structure', subsection 'Keywords and Punctuation')
I will be downloading the Xcode 7 beta later today, at which time I will test this to verify, and will update here after I've done so.
Yeah, I'm downloading too. This would suck if true, but such is life.
so is defer
Oh FFS.
Options to replace catch:
p.then{ /*…*/ }.error { error in }p.then{ /*…*/ }.onfail { error in }p.then{ /*…*/ }.fail { error in }p.then{ /*…*/ }.failed { error in }p.then{ /*…*/ }.clasp { error in }p.then{ /*…*/ }.onerror { error in }
Options for defer:
let (promise, fulfill, reject) = Promise<Int>.deferred()let (promise, fulfill, reject) = Promise<Int>.tuple()let (promise, fulfill, reject) = Promise<Int>.breakOut()let (promise, fulfill, reject) = Promise<Int>.split()
FWIW:
For catch replacement, I like fail or failed.
For defer replacement I like deferred(). My rationale for this is that using the alternate form:
let deferred = Promise<Int>.deferred()
seems more natural than the other alternatives, as would accessing it's members:
deferred.promise, deferred.fulfil, deferred.reject.
fail is not my favorite, it doesn’t read as well as catch. I'm still thinking of more ideas, the above list is not the final list.
Coming from JS promises, deferred was sometimes used and seems like a natural replacement. fail was also used by jQuery in place of catch, though their promises aren't compliant. Not that javascript needs to have any influence on whatever you decide.
Preliminary swift 2.0 branch here: https://github.com/mxcl/PromiseKit/tree/swift-2.0
It compiles, some UI tests are disabled. The name snatch is not final.
What about rescue? This is used in Ruby and I guess some other languages.
IMO It's give a good insight of what it is doing, juste like catch
The current branch is now rescue. Though I'm not 100% sure yet since PromiseKit doesn't rescue errors, since the app survives if you don't.
I pushed some additional revisions so you can throw in most swift methods.
Not really sure that rescue is a great name for the new catch which @mxcl has already mentioned doesn't actually rescue from errors. Additionally there is already a recover feature which does rescue from errors and recovery is a synonym for rescue
Also, Swift “exceptions” don’t crash the app either; instead you must handle them, you cannot write code that does not.
Ideally we’d keep the same pattern for Promise, but I fail to see how that can be done since we are not writing the compiler.
Has the decision been made yet? If not, what about
p.then{ /*…*/ }.ifFailed { error in }
p.then{ /*…*/ }.whenFailed { error in }
?
No decision. I'm having sleepless nights about it.
As for defer, I haven't used it much, so I might not completely understand its meaning, but handle (as in door handle) seems like a candidate to me:
let (promise, fulfill, reject) = Promise<Int>.handle() or
let (promise, fulfill, reject) = Promise<Int>.createHandle()
Or maybe some other, better name for object which can be used to do stuff.
For defer I made it pendingPromise which is more Cocoa like anyway.
I think I’m happy with report:
spinner.start()
when(fetchImage(), getLocation()).then { image, location in
self.imageView.image = image;
self.label.text = "Buy your cat a house in \(location)"
}.ensure {
spinner.stop()
}.report { error in
UIAlertView(…).show()
}
I changed finally to ensure since we had to change away from catch and finally is from the try, catch, finally pattern. And finally was a lie with the Swift version since 2.0 anyway since you couldn't do it after a catch.
I will probably add ensure and report as aliases for AnyPromise, but I don't wish to force the change when not necessary for all users.
Opinions welcome.