{"id":30893,"date":"2020-11-30T16:36:15","date_gmt":"2020-11-30T21:36:15","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=30893"},"modified":"2020-11-30T16:36:15","modified_gmt":"2020-11-30T21:36:15","slug":"what-is-not-so-great-about-swiftui","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/11\/30\/what-is-not-so-great-about-swiftui\/","title":{"rendered":"What Is Not So Great About SwiftUI"},"content":{"rendered":"<p><a href=\"https:\/\/tclementdev.com\/posts\/what_is_not_so_great_about_swiftui.html\">Thomas Clement<\/a> (<a href=\"https:\/\/twitter.com\/tclementdev\/status\/1332352833677647876\">tweet<\/a>):<\/p>\n<blockquote cite=\"https:\/\/tclementdev.com\/posts\/what_is_not_so_great_about_swiftui.html\"><p>What seems to still be missing from SwiftUI is the notion of the intrinsic content size: the natural size that a view really wants to be unless it is forced to be something else. This is the size that views should adopt by default. Working in-hand with this would be the ability to define compression resistance priorities and content hugging priorities, something that SwiftUI also lacks. These are important features to describe how views should behave relative to each others when they are forced to deviate from their natural size.<\/p>\n<p>[&#8230;]<\/p>\n<p>You heard that right: merely looking at the size proposed by the parent will change the layout in unwanted ways.<\/p>\n<p>[&#8230;]<\/p>\n<p>It is bothering that third-party developers are not able to write the same kind of views that Apple provides in SwiftUI.<\/p>\n<p>[&#8230;]<\/p>\n<p>But the SwiftUI code only builds a description of the wrapper view, there is no function that can directly be called to talk to the underlying AppKit view. The natural SwiftUI way of doing this would be to add a new state variable such as <code>@State var isAuthorized: Bool<\/code> and pass it along to the view representable but alas this really doesn&rsquo;t work well as the <code>SFAuthorizationView<\/code> owns the state already (the authorization reference). There is no obvious way that I know to address this sort of discrepancies.<\/p><\/blockquote>\n\n<p>I still don&rsquo;t know what to think about SwiftUI. Much of it seems amazing, but two major releases in there&rsquo;s this basic stuff that remains broken, and stuff that was easy with Auto Layout is needlessly difficult or impossible. How much is just bugs vs. limitations of the overall system&rsquo;s design? For the latter, is the long-term plan that some UIs are just not possible? Or that AppKit\/UIKit will live forever?<\/p>\n<p>With Auto Layout, you could always opt out certain subtrees if what you were trying to do was too slow or couldn&rsquo;t be expressed. But, as Clement describes, SwiftUI&rsquo;s <code>NSViewRepresentable<\/code> isn&rsquo;t the same kind of escape hatch.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/SteveStreza\/status\/1333203169501798401\">Steve Streza<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/SteveStreza\/status\/1333203169501798401\"><p>SwiftUI on Mac is a constant struggle of wondering &ldquo;am I doing this wrong or is this just broken on Mac&rdquo;<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\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\/08\/10\/swiftui-alerts\/\">SwiftUI Alerts<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/08\/06\/emulating-equal-size-constraints-in-swiftui\/\">Emulating Equal-Size Constraints in 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\/06\/08\/why-textview-is-my-swiftui-canary\/\">Why TextView Is My SwiftUI Canary<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Thomas Clement (tweet): What seems to still be missing from SwiftUI is the notion of the intrinsic content size: the natural size that a view really wants to be unless it is forced to be something else. This is the size that views should adopt by default. Working in-hand with this would be the ability [&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-11-30T21:36:18Z","apple_news_api_id":"c01a90a7-8756-4368-a9d5-97518445eb59","apple_news_api_modified_at":"2020-11-30T21:36:19Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/AwBqQp4dWQ2ip1ZdRhEXrWQ","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":[200,69,31,1837,30,1891,71,1812],"class_list":["post-30893","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-autolayout","tag-cocoa","tag-ios","tag-ios-14","tag-mac","tag-macos-11-0","tag-programming","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30893","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=30893"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30893\/revisions"}],"predecessor-version":[{"id":30894,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30893\/revisions\/30894"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=30893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=30893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=30893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}