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 me
Just to add clarification to this rather over complicated workaround: can anyone see why the below is not firing/working when the action is being taken?
extension AppDelegate: UNUserNotificationCenterDelegate {
@objc(userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("RESPONSE FROM NOTIFICATION!")
switch response.actionIdentifier {
case "reply":
print("Reply action received!")
case "ignore":
print("Ignore action received!")
default: print("Error - Unknown action received!")
break
}
}
}
Another cause of this warning when NSError
is being bridged to Swift:
Given this Objective-C delegate method:
- (void)myService:(id<MYService>)myService didFailForSomeReason:(NSError *)error;
That automatically generates this Swift method:
public func myService(_ myService: MYService!, didFailForSomeReason error: Error!)
The warning was shown.
In my case the reason was that my class had it's own Error
type so the signature was resolving to MyClass.Error
rather than Swift.Error
. The solution was to fully type the Error parameter by changing it to Swift.Error
:
public func myService(_ myService: MYService!, didFailForSomeReason error: Swift.Error!)
Here's what fixed it for me.
I was getting the same warning in some code that I was sure that I typed into the editor initially and allowed it to autocomplete. I subsequently went back and re-visted the warning and tried to just type the same function over again right after my existing function. When I entered the function name over again, my function signature changed and the parms matched up exactly with what Xcode expected and the warning was suppressed.
So if you want to do a quick sanity check, do yourself a favor and try typing in the function one more time and see if the parm types change. That might be all you need.
for me the problem was custom Error
class
Basically I had my own class with name Error
and compiler was considering delegate method
as a local method
I just changed name of my own class name and it worked. So, just confirm that you don't have any class name same in the function