I recently compiled my macOS App with Swift 6 in Xcode 16 (was using Swift 5 previously) and noticed that AppKit Integration doesn't appear to be working as before. All my instances of NSHostingView which allow me to add a SwiftUI View to an AppKit NSWindow view controller no longer respond to mouse input anymore. All my NSHostingView instances display but refuse to accept any user interaction. Has anyone else noticed this and is there a workaround to get NSHostingView to once again be able to accept user/mouse events with Swift 6?
Here is the solution I found. When using NSHostingView to wrap a SwiftUI View to use with AppKit, don't set the SwiftUI View x and y position parameters within the SwiftUI View itself. If you do, the NSHostingView will visually render properly but the NSEvent handling area for the NSHostingView will be offset and it won't respond to mouse events (it did work fine back in macOS 14). Only set the width and height parameters in the SwiftUI View and then when you have the resulting NSHostingView of that, you can set the NSHostingView frame parameter to properly place it on an NSWindow. Presumably this is an API bug. NSHostingView is supposed to do the correct coordinate transform on the SwiftUI View to make it into a usable NSHostingView but this is no longer the case with macOS 15. Use this solution if you have the same error because it took me days to find this solution.