IOS warning: instance method 'userNotificationCenter(_:willPresent:withCompletionHandler:)' nearly matches optional requirement

In an iOS project, I have implemented the following delegate method to handle Notifications when app is in foregorund:

func userNotificationCenter (_ pNotificationCenter : UNUserNotificationCenter, willPresent pNotification : UNNotification, withCompletionHandler pCompletionHandler : @escaping (UNNotificationPresentationOptions) -> Void) -> Void
{
    // When app is in foreground, notification is directly sent to 
    // the app by invoking this delegate method. 
}

When building, I'm getting the warning. But my implementation is correct according to documentation.

Why is this method not recognized as the implementation of the UNUserNotificationCenterDelegate protocol?

This is the warning in text format:

Showing All Issues
<file path & line number>: Instance method 'userNotificationCenter(_:willPresent:withCompletionHandler:)' nearly matches optional requirement 'userNotificationCenter(_:willPresent:withCompletionHandler:)' of protocol 'UNUserNotificationCenterDelegate'

This is the image of the warning:

Am I missing some flag in a compiler setting?

My env: Xcode 15.2, Swift 5.0, Deployment target - iOS 14.0+.

That’s weird. I tried your code in an otherwise empty class and got no warning. Can you show how the class itself is declared: the superclass, other protocols implemented, any attributes like @MainActor, etc.? Do you get the same warning if you implement this protocol method in an otherwise empty class in your project?

I'm seeing the same here. Xcode 15.3, Swift 5.0, Min SDK iOS 14.0

The accepted signature is:

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (Int) -> Void) {
        <#code#>
    }

where instead of UNNotificationPresentationOptions there's Int

Solved it by calling the completionHandler with an explicit Int value (i.e. completionHandler(1 << 4) for banner)

IOS warning: instance method 'userNotificationCenter(_:willPresent:withCompletionHandler:)' nearly matches optional requirement
 
 
Q