{"id":28108,"date":"2020-02-11T16:21:41","date_gmt":"2020-02-11T21:21:41","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=28108"},"modified":"2020-02-26T14:14:23","modified_gmt":"2020-02-26T19:14:23","slug":"more-about-swiftui","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/02\/11\/more-about-swiftui\/","title":{"rendered":"More About SwiftUI"},"content":{"rendered":"<p><a href=\"https:\/\/developer.apple.com\/tutorials\/swiftui\/creating-a-macos-app\">Apple<\/a> (via <a href=\"https:\/\/twitter.com\/tonyarnold\/status\/1224632499633967105\">Tony Arnold<\/a>):<\/p>\n<blockquote cite=\"https:\/\/developer.apple.com\/tutorials\/swiftui\/creating-a-macos-app\"><p>You&rsquo;ll start by adding a macOS target to your project, and then reusing the shared data you created for the iOS app. With all of the assets in place, you&rsquo;ll create SwiftUI views to display list and detail views on macOS.<\/p>\n<p>Follow the steps to build this project, or download the finished project to explore on your own.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/www.objc.io\/blog\/2020\/02\/03\/thinking-in-swiftui\/\">Chris Eidhof<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.objc.io\/blog\/2020\/02\/03\/thinking-in-swiftui\/\">\n<p>After a few months spent delving into SwiftUI, we decided to write a short book: it&rsquo;s called <a href=\"https:\/\/www.objc.io\/books\/thinking-in-swiftui\">Thinking in SwiftUI<\/a>. Since SwiftUI is still in its early days, the book focuses on the concepts behind the framework that we believe are essential to understand. It is not a reference for SwiftUI&rsquo;s platform-specific APIs, but rather a guide to honing your intuition about how SwiftUI works.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/tonsky.me\/blog\/swiftui\/\">Nikita Prokopov<\/a> (<a href=\"https:\/\/news.ycombinator.com\/item?id=22413355\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/tonsky.me\/blog\/swiftui\/\">\n<p>First, the general approach SwiftUI is taking (reactive declarative data-driven UI framework) is really solid and considered state-of-the-art as of the current day of the year. No complaints here, great job, we all needed that, thank you Apple for releasing it. No, seriously. It&rsquo;s a great tool and I&rsquo;m looking forward to using it.<\/p>\n<p>But, a few things I noticed in SwiftUI concern me. I think they could illustrate points in the UI framework design that future systems could handle better. Without further ado, let&rsquo;s start with the biggest problem in API design: commas!<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/will.townsend.io\/2019\/an-intro-to-swiftui-button-styles\">Will Townsend<\/a>:<\/p>\n<blockquote cite=\"https:\/\/will.townsend.io\/2019\/an-intro-to-swiftui-button-styles\"><p>Today I&rsquo;ll explain how to create your own Button Styles, and hopefully show you the difference between <code>ButtonStyle<\/code> and <code>PrimitiveButtonStyle<\/code>, and why you&rsquo;d use one or the others.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/netsplit.com\/swiftui\/views-choose-their-own-sizes\/\">Scott James Remnant<\/a> (via <a href=\"http:\/\/www.figure.ink\/blog\/2019\/9\/2\/swiftui-layout-gems\">Joshua Emmons<\/a>):<\/p>\n<blockquote cite=\"https:\/\/netsplit.com\/swiftui\/views-choose-their-own-sizes\/\">\n<p>One of the first things presented about SwiftUI is that its views choose their own sizes, and that once chosen, those choices cannot be overridden. This is such a simple statement that it would be easy to move on quickly to get to the good stuff.<\/p>\n<p>This would be a mistake, because this simple statement fundamentally changes everything you know about layout.<\/p>\n<p>[&#8230;]<\/p>\n<p>This doesn&rsquo;t contradict what we&rsquo;ve just learned about chosen sizes not being able to be overridden, it actually demonstrates another key principle we haven&rsquo;t learned yet: a view receives a proposed size from its parent before it chooses its own size.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/kean.github.io\/post\/swiftui-layout-system\">Alexander Grebenyuk<\/a>:<\/p>\n<blockquote cite=\"https:\/\/kean.github.io\/post\/swiftui-layout-system\">\n<p>SwiftUI no longer uses Auto Layout, gone all of the cruft introduced over the years. SwiftUI has a completely new layout system designed from the ground up to make it easy to write adaptive cross-platform apps. [&#8230;] I can&rsquo;t be more excited to dig deep into the SwiftUI layout system to see what it has to offer.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/olebegemann\/status\/1212731795264999424\">Ole Begemann<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/olebegemann\/status\/1212731795264999424\">\n<p>SwiftUI&rsquo;s layout algorithm may be simple on the surface, but the way the built-in views and view modifiers interact is tremendously complex (and largely undocumented).<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/swiftui-lab.com\/alignment-guides\/\">Javier<\/a>:<\/p>\n<blockquote cite=\"https:\/\/swiftui-lab.com\/alignment-guides\/\">\n<p>After spending some time testing the limits of alignment guides, I arrived at the conclusion that they do work. However, there&rsquo;s confusion about what we expect from them. This confusion comes from not realizing there&rsquo;s a whole set of implicit alignment guides in effect. When we ignore them, things do not go our way.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/swiftui-lab.com\/equatableview\/\">Javier<\/a>:<\/p>\n<blockquote cite=\"https:\/\/swiftui-lab.com\/equatableview\/\">\n<p>In this short article, we are going to explore several aspects of View equality. We&rsquo;ll see what happens when we make a view conform to Equatable, and what is the purpose of EquatableView and the .equatable() modifier.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/swiftui-lab.com\/state-changes\/\">Javier<\/a>:<\/p>\n<blockquote cite=\"https:\/\/swiftui-lab.com\/state-changes\/\">\n<p>If you&rsquo;ve been using SwiftUI for a while now, you probably hit the problem where you find yourself trying to update the state of a view from inside its body. Usually, Xcode complains during runtime. When it does, you are forced to put your update inside a DispatchQueue closure (not feeling too good about yourself) but you carry on anyway. Does this sound familiar? In this article, we&rsquo;ll discuss why it sometimes is perfectly fine to apply that technique, but some other times, it&rsquo;s a no-no (leading to CPU spikes or app crashes).<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/jsorge.net\/2019\/09\/03\/examples-of-my-swiftui-struggles\">Jared Sorge<\/a>:<\/p>\n<blockquote cite=\"https:\/\/jsorge.net\/2019\/09\/03\/examples-of-my-swiftui-struggles\">\n<p>In my <a href=\"https:\/\/jsorge.net\/2019\/08\/22\/struggling-with-swiftui\">last post<\/a> I talked about some of the struggles I&rsquo;m having getting up to speed with SwiftUI. Let&rsquo;s dive in to a couple of examples.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/rwapp.co.uk\/2019\/11\/06\/SwiftUI-Accessibility\/\">Rob Whitaker<\/a>:<\/p>\n<blockquote cite=\"https:\/\/rwapp.co.uk\/2019\/11\/06\/SwiftUI-Accessibility\/\">\n<p>Apple has taken the chance to re-think how some of their accessibility tools work for developers, and they&rsquo;ve baked in accessibility right from the very beginning. Apple&rsquo;s accessibility teams have been an integral part of some of the decisions that have shaped SwiftUI. You can see this throughout your SwiftUI code.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/nshipster.com\/swiftui-previews\/\">Mattt Thompson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/nshipster.com\/swiftui-previews\/\">\n<p>It&rsquo;s hard to overstate how much of a game-changer Xcode Previews are for iOS development, and we couldn&rsquo;t be happier to incorporate them into our workflow.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/k_katsumi\/status\/1214298713524359169\">Kishikawa Katsumi<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/k_katsumi\/status\/1214298713524359169\">\n<p>I published <a href=\"https:\/\/swiftui-playground.kishikawakatsumi.com\">SwiftUI online playground<\/a>.<\/p>\n<p>You can try SwiftUI and see the rendering results insanely easily.&#x1F60A;<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/tclementdev\/status\/1223372823332380673\">Thomas<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/tclementdev\/status\/1223372823332380673\">\n<p>I tried to replicate my app&rsquo;s GUI using SwiftUI. Couldn&rsquo;t get the basic layout right: standard controls do not size themselves correctly. Also, popup buttons do not draw their menu correctly. SwiftUI is plain broken on macOS.<\/p>\n<\/blockquote>\n\n<p>I continue to hear about problems like this.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/wooji\/status\/1197551664582012928\">Wooji Juice<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/wooji\/status\/1197551664582012928\">\n<p>If you want to make a Mac app, there are <em>4<\/em> primary APIs you could be using, in a sorta 2x2 grid: AppKit, UIKit (w\/Catalyst), SwiftUI-in-AppKit, SwiftUI-in-UIKit. It&rsquo;s a complex mess of what each does\/doesn&rsquo;t support &mdash; figuring out which to use for any given UI is trial &amp; error<\/p>\n<p>I&rsquo;ve been trying to make one relatively simple bit of UI (in a standalone testbed app) for days. Every time I think I&rsquo;m on a roll, I bump into a different wall of missing functionality. I try different implementations. I try different designs that don&rsquo;t need same features.<\/p>\n<p>It&rsquo;s not even like you can say &ldquo;Screw it, I&rsquo;ll do everything old-school pure native AppKit and get access to everything&rdquo;, cuz you&rsquo;ll still be missing some things (e.g. SF Symbols aren&rsquo;t supported, even tho they are all available on Mac since Catalyst apps can use them).<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/01\/31\/swiftui-for-mac\/\">SwiftUI for Mac<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/12\/13\/swiftui-deal-breakers\/\">SwiftUI Deal-Breakers<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2019\/10\/22\/swiftui-is-still-the-future\/\">SwiftUI Is Still the Future<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Apple (via Tony Arnold): You&rsquo;ll start by adding a macOS target to your project, and then reusing the shared data you created for the iOS app. With all of the assets in place, you&rsquo;ll create SwiftUI views to display list and detail views on macOS. Follow the steps to build this project, or download 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":"2020-02-11T21:21:45Z","apple_news_api_id":"7ac8a953-4437-4c62-87e1-6a6ca65a59e4","apple_news_api_modified_at":"2020-02-26T19:14:28Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAg==","apple_news_api_share_url":"https:\/\/apple.news\/AesipU0Q3TGKH4WpsplpZ5A","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":[930,200,63,164,30,1666,71,1812],"class_list":["post-28108","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-accessibility","tag-autolayout","tag-book","tag-documentation","tag-mac","tag-macos-10-15","tag-programming","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28108","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=28108"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28108\/revisions"}],"predecessor-version":[{"id":28226,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/28108\/revisions\/28226"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=28108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=28108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=28108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}