@MainActor app delegate

My app delegate is marked as @MainActor.

@main
@MainActor
class AppDelegate: NSObject, NSApplicationDelegate {

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application
    }

    ...

}

Since Swift 5.6 (Xcode 13.3 beta 2; 13E5095k) I get warnings like

Instance method 'applicationDidFinishLaunching' isolated to global actor 'MainActor' can not satisfy corresponding requirement from protocol 'NSApplicationDelegate

What is the correct way to handle them?

Notes:

  • @_predatesConcurrency import AppKit does not help and @_predatesConcurrency extension AppDelegate: NSApplicationDelegate { ... } does not work.
  • It's the same with the last 5.6 development snapshot (Swift 5.6 Development Snapshot 2022-02-11 (a)) and @preconcurrency.

That method does seem to be guaranteed to be run on the main actor, so this warning is incorrect, presumably because the SDK is missing the right attributes. @Douglas_Gregor may know if there's a way to suppress it in the short term.

Got several of these too. Is there any solution? Thanks!

For me (Monterey 12.5.1 on a M1 Mac, Xcode 13.4.1) it worked to put the delegate methods in an extension of AppDelegate conforming to NSApplicationDelegate

Then the warnings disappeared.

I have the same issue, and I tried the extension trick from @vadian. It worked in Xcode 13.4.1, but not in Xcode 14 beta 6 (I'm also on Monterey 12.5.1).