I'm trying to convert a Swift 2.2 project to Swift 3, and I'm getting the following error:
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
On my function whose signature is:
func observeValue(forKeyPath keyPath: String?, ofObject: Any?, change: [String : Any]?, context: UnsafeMutableRawPointer?)."
I have read the advice on the Swift 3 Migration Guide web site:
"Workaround: Add an @objc(objectiveC:name:) attribute before the implementation of the optional requirement with the original Objective-C selector inside."
But it isn't clear to me how this is actually supposed to be applied in a source file, and nothing I have tried so far has worked successfully.
Can anyone explain how to set this up properly?
This is what (finally) worked for me using Swift 3.0 in Xcode Version 8.0 (8A218a):
@objc
override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With