Testing SwiftUI for Mac After WWDC 2022
In December 2019, I wrote a series of articles about using SwiftUI to build a Mac app. And in July 2020, I re-visited the sample app to apply the new SwiftUI features made available in macOS BigSur. Now that macOS Ventura and Xcode 14 are in beta, it’s time to build the app again while learning how to incorporate the new APIs.
[…]
macOS apps can have multiple windows open at once, and in previous iterations of SwiftUI, it has been difficult to detect the active one. Last year, we got
@FocusedBinding
but it didn’t really work. This year it works, but we also have a newEnvironmentValue
calledcontrolActiveState
.[…]
This year, we have a new method that uses another new
EnvironmentValue
calledopenWindow
. […] If you create aWindow
scene instead of aWindowGroup
, not only does this become a single presentation window, but you get a menu item for it in the Window menu without any extra work. You can add a keyboard shortcut to theWindow
scene too. Supposedly, you can add default sizing and positioning, but they don’t appear to work yet.[…]
I achieved something I was unable to do last time and that is to make the text edit field have focus when the view opens.
Previously:
- Thoughts on SwiftUI After WWDC 2022
- SwiftUI Changes at WWDC 2022
- SwiftUI in 2022
- The State of SwiftUI
- SwiftUI for Mac on Big Sur
- SwiftUI for Mac
Update (2022-06-24): Thomas Clement:
Unfortunately, [
List
has the] same terrible perf in Ventura.
Update (2022-07-05): See also: Hacker News.