{"id":28001,"date":"2020-01-31T16:29:38","date_gmt":"2020-01-31T21:29:38","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=28001"},"modified":"2020-01-31T16:29:38","modified_gmt":"2020-01-31T21:29:38","slug":"swiftui-for-mac","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/01\/31\/swiftui-for-mac\/","title":{"rendered":"SwiftUI for Mac"},"content":{"rendered":"<p><a href=\"https:\/\/troz.net\/post\/2019\/swiftui-for-mac-1\/\">Sarah Reichelt<\/a> (via <a href=\"https:\/\/twitter.com\/olebegemann\/status\/1222873242152718337\">Ole Begemann<\/a>):<\/p>\n<blockquote cite=\"https:\/\/troz.net\/post\/2019\/swiftui-for-mac-1\/\"><p>So far, nearly all the articles I have seen about SwiftUI show it being used for iOS, more particularly for iPhone. But SwiftUI works on all Apple&rsquo;s platforms, and as I am primarily a Mac developer, I decided to try out a Mac app and see what happened.<\/p>\n<p>[&#8230;]<\/p>\n<p>If I changed the structure of the view, the app closed and re-opened immediately with the new content. This is amazing and shows that the Xcode &amp; SwiftUI teams really thought about how to use these new features in Mac apps as well as iOS.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/troz.net\/post\/2019\/swiftui-for-mac-2\/\">Sarah Reichelt<\/a>:<\/p>\n<blockquote cite=\"https:\/\/troz.net\/post\/2019\/swiftui-for-mac-2\/\">\n<p>I had already discovered that the menu bar is configured in the Main.storyboard file.<\/p>\n<p>[&#8230;]<\/p>\n<p>In this case, it would make more sense to have the DetailView respond to the menu, since it contains the image. But trying to add an @IBAction to a SwiftUI View struct gives this error: <code>Only instance methods can be declared @IBAction<\/code> so I am using the App Delegate instead. I feel like this is a problem I need to solve, or the AppDelegate is going to end up filled with @IBActions, but for now, let&rsquo;s keep going.<\/p>\n<p>[&#8230;]<\/p>\n<p>Not all the expected user interface elements are available in SwiftUI and some of the ones that are implemented are using different names. Again this is a point at which iOS development has got all the attention, so there are conversion tables out there listing UIKit elements and their SwiftUI equivalents, but I was not able to find a similar listing for AppKit. If you find one, please let me know.<\/p>\n<p>[&#8230;]<\/p>\n<p>And I was not able to set a button as the default button and I could not work out how to set a keyboard equivalent for a button.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/troz.net\/post\/2019\/swiftui-for-mac-3\/\">Sarah Reichelt<\/a>:<\/p>\n<blockquote cite=\"https:\/\/troz.net\/post\/2019\/swiftui-for-mac-3\/\">\n<p>In this third and final part, I want to look at the various ways to present dialogs to the user.<\/p>\n<p>[&#8230;]<\/p>\n<p>To make an Alert, I need an @State Bool which sets whether the alert is visible or not. All the button has to do is toggle that Bool.<\/p>\n<p>[&#8230;]<\/p>\n<p>The trick to dismissing the sheet is to pass it a Binding to the Bool that triggered it to open in the first place. If a button in the sheet sets this Bool back to false, the parent view will hide the sheet. That sounds confusing, but it works.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/troz.net\/post\/2020\/swiftui_for-mac-extras\/\">Sarah Reichelt<\/a>:<\/p>\n<blockquote cite=\"https:\/\/troz.net\/post\/2020\/swiftui_for-mac-extras\/\">\n<p>I would like to thank everyone who contacted me about this series. It was received very well and revealed that there is still a large amount of interest in programming for the Mac.<\/p>\n<p>Some of the responses I got were pointing out different or better ways to do things, so I am going to list them here, adding to this post as I get new information.<\/p>\n<\/blockquote>\n\n<p>See also: <a href=\"https:\/\/troz.net\/post\/2019\/swiftui_first-thoughts\/\">SwiftUI First Thoughts<\/a> and <a href=\"https:\/\/troz.net\/post\/2019\/swiftui-data-flow\/\">SwiftUI Data Flow<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Sarah Reichelt (via Ole Begemann): So far, nearly all the articles I have seen about SwiftUI show it being used for iOS, more particularly for iPhone. But SwiftUI works on all Apple&rsquo;s platforms, and as I am primarily a Mac developer, I decided to try out a Mac app and see what happened. [&#8230;] If [&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":"2020-01-31T21:29:41Z","apple_news_api_id":"fc2b7f44-da4c-4001-a2b2-8d0aef162273","apple_news_api_modified_at":"2020-01-31T21:29:41Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/A_Ct_RNpMQAGiso0K7xYicw","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":[1813,30,1666,71,901,1812,226],"class_list":["post-28001","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-combine-framework","tag-mac","tag-macos-10-15","tag-programming","tag-swift-programming-language","tag-swiftui","tag-xcode"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28001","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=28001"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28001\/revisions"}],"predecessor-version":[{"id":28002,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28001\/revisions\/28002"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=28001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=28001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=28001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}