使用swift3遇到一些问题 - > swift4转换。这是转换前的原始代码:
NotificationCenter.default.addObserver(self, selector: #selector(DataCollectionViewController.playerItemDidReachEnd), name: Notification.Name.AVPlayerItemDidPlayToEndTime, object: carVideoPlayer?.currentItem)
_ = observe(notificationName: Notification.Name.UIApplicationDidBecomeActive) {
_ in
if recorder.tripRunning {
self.carVideoPlayer?.play()
}
}
_ = observe(notificationName: Notification.Name.UIApplicationDidEnterBackground) {
_ in
self.carVideoPlayer?.pause()
}
_ = observe(notificationName: .tripStopped) {
_ in
self.carVideoPlayer?.pause()
}
转换后,我遇到调用observe的行的语法问题; "通用参数'价值'无法推断"。有谁知道这个的原因? Swift 4的编译器说参数标签是无关的,闭包类型需要2个参数。 这是转换后的代码:
NotificationCenter.default.addObserver(self, selector: #selector(DataCollectionViewController.playerItemDidReachEnd), name: Notification.Name.AVPlayerItemDidPlayToEndTime, object: carVideoPlayer?.currentItem)
_ = observe(Notification.Name.UIApplicationDidBecomeActive) {
_,_ in
if recorder.tripRunning {
self.carVideoPlayer?.play()
}
}
_ = observe(Notification.Name.UIApplicationDidEnterBackground) {
_,_ in
self.carVideoPlayer?.pause()
}
_ = observe(.tripStopped) {
_,_ in
self.carVideoPlayer?.pause()
}