所以我在我最新的 swift 应用程序中使用 PromiseKit 和 Alamofire 来完成大部分网络代码。当我的回报不是我想要的时,我正在尝试设置我的承诺 - 这是代码的样子:
`
do{
firstly({
try DoStuff.doStuff()
}).then({ response in
self.array = response
}).error { error in
throw Error.GeneralError
print(error)
}
firstly({
try DoOtherThing.otherThing()
}).then({ response in
self.stuff = response
}).error{ error in
throw TransactionError.GeneralError
print(error)
}
} catch {
let alertController = UIAlertController(title: "Network Error", message: "Network error, please try again", preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Default) { (action) in
//
}
alertController.addAction(OKAction)
self.presentViewController(alertController, animated: true) {
//
}
}
`
如果我在那里没有“抛出”语句,那么这段代码就可以正常工作——如果我只是打印错误,或者把我的警报控制器代码放在那里,就可以按预期工作。但是当我添加抛出时,我在“错误”行上得到一个编译器红旗,上面写着有Cannot call value of non function type 'ErrorType'
什么想法吗?谢谢