CVa*_*Var 5 migration syntax notificationcenter swift
我在尝试将我的代码片段从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)
}
Run Code Online (Sandbox Code Playgroud)
这是我设法做的事情:
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow), name: NSNotification.Name.UIResponder.UIKeyboardWillShowNotification, object: nil)
}
Run Code Online (Sandbox Code Playgroud)
我仍然得到错误:
Type of expression is ambiguous without more context
Run Code Online (Sandbox Code Playgroud)
我一整天都在编码,所以我甚至无法看到这段代码出了什么问题.任何人都可以帮我解决这个问题吗?
OOP*_*Per 13
你制造的东西太复杂了......
使用此代码,Xcode 10将向您显示正确的修复建议.
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow),
name: UIKeyboardWillShowNotification, object: nil)
}
Run Code Online (Sandbox Code Playgroud)
我的Xcode 10已将其修复为:
fileprivate func observeKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShow),
name: UIResponder.keyboardWillShowNotification, object: nil)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5203 次 |
| 最近记录: |