我很难将代码从Swift 3迁移到Swift 4.2
下面是要迁移的当前代码:
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardHide), name: .UIKeyboardWillHide, object: nil)
}以下是我所做的工作:
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow), name: NSNotification.Name.UIResponder.UIKeyboardWillShowNotification, object: nil)
}但我还是发现了一个错误:
Type of expression is ambiguous without more context我一整天都在编写代码,所以我甚至都看不出这段代码有什么问题。有人能帮我解决这个问题吗?
发布于 2018-09-28 03:49:21
你把事情搞得太复杂了。
使用这段代码,Xcode 10将向您展示正确的修复-it建议。
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow),
name: UIKeyboardWillShowNotification, object: nil)
}我的Xcode 10已将其修复为:
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow),
name: UIResponder.keyboardWillShowNotification, object: nil)
}https://stackoverflow.com/questions/52547959
复制相似问题