I'm using Swift concurrency in my application. The application creates a window with a toolbar. NSToolbarDelegate must implement
func toolbar(
_ toolbar: NSToolbar,
itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,
willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem?
This method has to be nonisolated, otherwise you get a warning
Main actor-isolated instance method 'toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)' cannot be used to satisfy nonisolated protocol requirement
This method is designed to create a new NSToolbarItem. Apple docs:
Use this method to create new NSToolbarItem objects when the toolbar asks for them.
However, NSToolbarItem is isolated on @MainActor, so you have to call its constructor on @MainActor, which is impossible to do from a nonisolated method and still return a value from that method.
Is this a bug in the current version of AppKit or is there a workaround?