Not sure what i'm doing wrong but i returned a promise in one of my functions a Promise
myFunction().error() {
error -> Void in
print("My error: \(error.description)")
}
Does anyone know what i am doing wrong?
kind regards,
Daan
Don't use () it is confusing the swift compiler apparently.
So just .error {
In fact it is necessary to provide a parameter to the closure or the Swift compiler is confused with our error property:
.error { error in
This way it works with parenthesis too:
.error() { error in
Swift compiler bug.
I'm also seeing this confusing compiler error, and I can't make sense of what is confusing the Swift compiler so badly, but your suggestions (remove the ()) didn't work. However, after much playing around, I got it working...
With a func doThing() -> Promise<Void> and another func handleError(e: NSError), I tried:
firstly {
doThing()
}.then {
NSLog("DONE!")
}.error { (e) -> () in
// ^^^^^ Cannot call value of non-function type 'ErrorType?'
handleError(e)
}
But adding a second line to the method changed the error. Any second line would do, NSLog("error") or return were what I tried. The following gave a different error:
firstly {
doThing()
}.then {
NSLog("DONE!")
}.error { (e) -> () in
handleError(e)
// ^ Cannot convert value of type 'ErrorType' to expected
return
}
Which was easily enough fixed, and then I could remove the superfluous second line too:
firstly {
doThing()
}.then {
NSLog("DONE!")
}.error { (e) -> () in
handleError(e as NSError)
}
// Compiles fine
I hope this helps someone else who gets here via google. :smiley:
It did help at least one person. Thank you nevans!
Make that two. Been pulling my hair out on this. Thanks @nevans !!
Most helpful comment
I'm also seeing this confusing compiler error, and I can't make sense of what is confusing the Swift compiler so badly, but your suggestions (remove the
()) didn't work. However, after much playing around, I got it working...With a
func doThing() -> Promise<Void>and anotherfunc handleError(e: NSError), I tried:But adding a second line to the method changed the error. Any second line would do,
NSLog("error")orreturnwere what I tried. The following gave a different error:Which was easily enough fixed, and then I could remove the superfluous second line too:
I hope this helps someone else who gets here via google. :smiley: