我正在尝试将我的应用程序从Swift 1.2转换为Swift 2.0,我遇到以下错误:
class B {
func test() -> Promise<A> {
return Promise<A> { (fulfill, reject) -> Void in
anotherPromise.then { _ -> Void in
return fulfill(A()) // Class declaration cannot close over value 'fulfill' defined in outer scope
}
}
}
}
如何让B
(或then
关闭)正确捕获fulfill
?
PS:Promise
来自PromiseKit,我正在运行Xcode 7 beta 1.
答案 0 :(得分:3)
您应该可以通过将class B {
func test() -> Promise<A> {
return Promise<A> { (fulfill, reject) -> Void in
let innerFulfill = fulfill // close on this instead
anotherPromise.then { _ -> Void in
return innerFulfill(A()) // Class declaration cannot close over value 'fulfill' defined in outer scope
}
}
}
}
分配给您捕获的本地来解决此问题。
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);