【发布时间】:2018-07-27 09:38:00
【问题描述】:
我是 Swift-Universe 中的菜鸟,但我必须让应用程序运行 ;) 如果您能帮助我找到解决方案,那就太好了。提前非常感谢。
升级到较新版本的 X-Code(版本 9.4.1)和 Swift 4 后会出现问题。
private var stoppedSuccessfully: (() -> Void)?
func stopRecording() -> Promise<Void> {
return Promise { success, _ in
self.stoppedSuccessfully = success // The error occors here: Cannot assign value of type '(Void) -> Void' to type '(() -> Void)?'
if WCSession.default.isReachable {
logger.info("Watch is reachable - Send Stop recording message.")
let command = RecordingCommand.stop
self.sendMessage(command, EvomoWatchConnectivityCore.WatchConnectivityCoreMethod.transferUserInfo,
nil, nil)
// Create a Timeout
let timeoutDelay: Double = 15
DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + timeoutDelay) {
if self.stoppedSuccessfully != nil {
self.logger.warning("### Stopped waiting for Apple Watch recording by Timeout!")
success(Void())
self.stoppedSuccessfully = nil
}
}
return
}
success(Void())
self.stoppedSuccessfully = nil
}
}
// In a other part of the code:
self.stoppedSuccessfully?()
self.stoppedSuccessfully = nil
【问题讨论】:
-
为什么要将成功块存储在变量中?
-
这段代码不是我写的。所以我无法回答你的问题。
-
我认为您也应该将库更新为 swift 4(包含
Promise的内容)。
标签: swift promisekit