【发布时间】:2016-08-25 04:27:47
【问题描述】:
我正在尝试将 Swift 2.2 项目转换为 Swift 3,但出现以下错误:
Method 'observeValue(forKeyPath:ofObject:change:context:)' with Objective-C selector 'observeValueForKeyPath:ofObject:change:context:' conflicts with method 'observeValue(forKeyPath:of:change:context:)' from superclass 'NSObject' with the same Objective-C selector" for the function call
在我的签名是:
func observeValue(forKeyPath keyPath: String?, ofObject: Any?, change: [String : Any]?, context: UnsafeMutableRawPointer?)."
我已阅读 Swift 3 迁移指南网站上的建议:
“解决方法:在执行可选要求之前添加一个@objc(objectiveC:name:) 属性,其中包含原始Objective-C 选择器。”
但我不清楚这实际上应该如何应用到源文件中,到目前为止我尝试过的任何方法都没有成功。
谁能解释一下如何正确设置?
【问题讨论】: