swift – Promise.onSuccess立即调用
发布时间:2020-12-14 04:59:47 所属栏目:百科 来源:网络整理
导读:我正在使用 BrightFutures,当我运行以下代码时,在geoCoder completionHandler完成之前调用sequence().onComplete和sequence().onSuccess.你能帮助我吗? self.uploadContentSequence = [FutureFutureVoid,NoError,NoError]();for post in posts { self.uploa
我正在使用
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 } 解决方法
正如phimage在本期杂志中所指出的那样:
https://github.com/Thomvis/BrightFutures/issues/111我将在未来完成未来.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |