Developers Call AppKit-SwiftUI Bridging a "Minefield"
Developers are voicing frustration with the state of SwiftUI on macOS, calling the AppKit bridging layer a "minefield." Key complaints include incorrect clipping in `NSHostingView` and half-baked toolbar customizations, forcing complex workarounds. In contrast, the same developer noted their iPad app, built with 95% SwiftUI, "works great," highlighting the divergence in framework maturity between platforms.
The underlying issue stems from AppKit's maturity as a framework compared to SwiftUI, which is still evolving on macOS. AppKit, the original toolkit for Mac development, is powerful and offers fine-grained control, but Apple has signaled that SwiftUI is the future. This leaves developers in a transitional period, often needing to mix both frameworks. Bridging is accomplished using `NSViewRepresentable` to wrap older AppKit views for use in SwiftUI, and `NSHostingView` or `NSHostingController` to embed new SwiftUI views within existing AppKit applications. While this allows for incremental adoption, managing state and interactions between the two different paradigms can be complex, leading to potential memory leaks, state synchronization bugs, and layout glitches. A significant change in macOS 14 (Sonoma) altered the default clipping behavior for `NSView`, the base class for all AppKit views. Previously, views would clip their contents to their bounds by default; now, `clipsToBounds` is `false` for apps linked against the new SDK. This can cause unexpected visual artifacts in hybrid apps where developers relied on the old clipping behavior, especially around custom drawing and complex view hierarchies. The developer experience on iPadOS is smoother because SwiftUI was designed with a more unified, modern UI framework (UIKit) as its foundation from the start. AppKit, predating iOS by decades, has a different architecture and set of conventions, making a seamless integration with the declarative SwiftUI model more challenging. Consequently, SwiftUI on macOS has fewer native components and requires falling back to AppKit more frequently for complex UIs. Toolbar customization in SwiftUI for macOS, while improved, still presents limitations that often require dropping down to AppKit. While modifiers like `.toolbar` and `ToolbarItem` provide basic structure, achieving specific layouts, item roles, or behaviors that are straightforward in AppKit can be difficult or impossible in pure SwiftUI. System-level decisions can also override developer preferences depending on the OS version and number of items. Looking ahead, Apple continues to invest heavily in SwiftUI with each new OS version, adding more native components and refining the framework's capabilities on macOS. At events like WWDC, the company has introduced features like "scene bridging" to better integrate SwiftUI scenes into AppKit app lifecycles. However, for performance-critical views or features that demand deep customization, developers will likely need to rely on the AppKit bridge for the foreseeable future.