I’ve run into a similar issue in a macOS app and ended up rethinking how to use SwiftUI’s focus system. The app has the usual triple-panel layout: sidebar, content, inspector. The content is two tables, either of which can be focused. Each table has a TableController, exposed via .focused(). The inspector reads the focused controller to update its display, and the sidebar shows its selection—both via @FocusedValue. On paper this works, but there’s a catch: when the sidebar or inspector itself gains focus (e.g. a text field), the focused table controller becomes nil. I tried various .focus modifiers but could never get the behaviour I wanted. What I really needed was a property influenced by focus but not identical to it. For example: Use the focused table controller if one exists. Otherwise fall back to the last focused table controller. Add other rules as needed. The solution was to introduce an active table controller managed by an @Observable object in the environment. The sidebar and inspector ob
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: