我正在使用BrightFutures,当我运行以下代码时,在geoCoder completionHandler完成之前调用sequence().onComplete
和sequence().onSuccess
。你可以帮助我让它运行吗?
self.uploadContentSequence = [Future<Future<Void, NoError>, NoError>]();
for post in posts {
self.uploadContentSequence.append(future(self.preparePostUpload(post)))
}
self.uploadContentSequence.sequence().onComplete { (_) -> Void in
print("onComplete")
}.onSuccess { (_) -> Void in
print("onSuccess")
}.onFailure { (_) -> Void in
print("onFailure")
}
[...]
func preparePostUpload(post: Post) -> Future<Void, NoError> {
let promise = Promise<Void, NoError>()
[...]
let postLocation = CLLocation(latitude: Double(post.lat!), longitude: Double(post.lng!))
let geocoder = CLGeocoder();
let countryCode = NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String
post.country = countryCode
geocoder.reverseGeocodeLocation(postLocation, completionHandler: { (placemarks, locError) -> Void in
[...]
promise.success()
});
return promise.future
}
答案 0 :(得分:1)
正如phimage在本期杂志中指出的那样:https://github.com/Thomvis/BrightFutures/issues/111我将在未来完成未来。