{"id":36312,"date":"2022-06-23T17:50:02","date_gmt":"2022-06-23T21:50:02","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=36312"},"modified":"2022-07-05T15:26:14","modified_gmt":"2022-07-05T19:26:14","slug":"testing-swiftui-for-mac-after-wwdc-2022","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2022\/06\/23\/testing-swiftui-for-mac-after-wwdc-2022\/","title":{"rendered":"Testing SwiftUI for Mac After WWDC 2022"},"content":{"rendered":"<p><a href=\"https:\/\/troz.net\/post\/2022\/swiftui-mac-2022\/\">Sarah Reichelt<\/a> (<a href=\"https:\/\/twitter.com\/trozware\/status\/1539859401653514240\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/troz.net\/post\/2022\/swiftui-mac-2022\/\">\n<p>In December 2019, I wrote a <a href=\"https:\/\/troz.net\/post\/2019\/swiftui-for-mac-1\/\">series of articles about using SwiftUI to build a Mac app<\/a>. And in July 2020, I <a href=\"https:\/\/troz.net\/post\/2020\/swiftui_mac_big_sur\/\">re-visited the sample app<\/a> to apply the new SwiftUI features made available in macOS BigSur. Now that macOS Ventura and Xcode 14 are in beta, it&rsquo;s time to build the app again while learning how to incorporate the new APIs.<\/p>\n<p>[&#8230;]<\/p>\n<p>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 <code>@FocusedBinding<\/code> but it didn&rsquo;t really work. This year it works, but we also have a new <code>EnvironmentValue<\/code> called <code>controlActiveState<\/code>.<\/p>\n<p>[&#8230;]<\/p>\n<p>This year, we have a new method that uses another new <code>EnvironmentValue<\/code> called <code>openWindow<\/code>. [&#8230;] If you create a <code>Window<\/code> scene instead of a <code>WindowGroup<\/code>, 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 the <code>Window<\/code> scene too. Supposedly, you can add default sizing and positioning, but they don&rsquo;t appear to work yet.<\/p>\n<p>[&#8230;]<\/p>\n<p>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.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/06\/17\/thoughts-on-swiftui-after-wwdc-2022\/\">Thoughts on SwiftUI After WWDC 2022<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/06\/17\/swiftui-changes-at-wwdc-2022\/\">SwiftUI Changes at WWDC 2022<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2022\/05\/24\/swiftui-in-2022\/\">SwiftUI in 2022<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/09\/18\/the-state-of-swiftui\/\">The State of SwiftUI<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/07\/14\/swiftui-for-mac-on-big-sur\/\">SwiftUI for Mac on Big Sur<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/01\/31\/swiftui-for-mac\/\">SwiftUI for Mac<\/a><\/li>\n<\/ul>\n\n<p id=\"testing-swiftui-for-mac-after-wwdc-2022-update-2022-06-24\">Update (2022-06-24): <a href=\"https:\/\/twitter.com\/tclementdev\/status\/1540266463445094401\">Thomas Clement<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/tclementdev\/status\/1540266463445094401\">\n<p>Unfortunately, [<code>List<\/code> has the] same terrible perf in Ventura.<\/p>\n<\/blockquote>\n\n<p>Update (2022-07-05): See also: <a href=\"https:\/\/news.ycombinator.com\/item?id=31967965\">Hacker News<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Sarah Reichelt (tweet): 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&rsquo;s time to build the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2022-06-23T21:50:05Z","apple_news_api_id":"21b0fa05-07e5-4fb1-8624-2262c3e31cdc","apple_news_api_modified_at":"2022-07-05T19:26:17Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAg==","apple_news_api_share_url":"https:\/\/apple.news\/AIbD6BQflT7GGJCJiw-Mc3A","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[30,2223,74,71,901,1812],"class_list":["post-36312","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-mac","tag-macos-13-ventura","tag-opensource","tag-programming","tag-swift-programming-language","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=36312"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36312\/revisions"}],"predecessor-version":[{"id":36425,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/36312\/revisions\/36425"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=36312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=36312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=36312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}