我一直在尝试使用 PromiseKit,但我一直在拒绝一个承诺。
Promise 拒绝是通过调用一个以 NSError 作为参数的拒绝函数来完成的。
func getAPromise() -> Promise<Bool> {
return Promise<Bool> { fulfiller, rejecter in
let diceRoll = Int(arc4random_uniform(7))
if diceRoll < 4 {
// rejecter(?) how do I call this rejection correctly ?
} else {
fulfiller(true)
}
}
简单地获取 NSError 的实例会对我有所帮助。
编辑:
NSError("somedomain", 123, [])
抱怨“通话中的额外参数”。