Xcode 8 Warning "Instance method nearly matches optional requirement"
I converted my (macOS) project to Swift 3 in Xcode 8 and I get the following warnings with several delegate methods I implement in swift classes:
Instance method 'someMethod' nearly matches optional requirement of protocol 'protocolName'
I get this for several NSApplicationDelegate methods like applicationDidFinishLaunching
and applicationDidBecomeActive
:
But also for implementations of tableViewSelectionDidChange
:
I used code completion to insert the method signatures and also tried copying them from the SDK-headers to rule out typos. The warnings just don't disappear and the methods are never called.
What am I missing here?
Solution 1:
We contacted Apple Developer Technical Support (DTS) with this issue. They replied that this is a bug in Xcode 8.
We submitted a bug report and hope for a quick update. (Apple Bug Report ID: 28315920).
If you experience a similar issue, please also file a bug report (referring to ours) so the Apple engineers see its not a single case.
Update for Xcode ≥ 8.1
The problem seems fixed now, at least for the delegate methods we are using in our project.
Solution 2:
After hours of searching I found this - Swift 3 ObjC Optional Protocol Method Not Called in Subclass
You can workaround the bug by prefixing the objective-c declaration on the function
@objc(tableViewSettingsDidChange:notification:)
func tableViewSettingsDidChange(_ notification:Notification)