{"id":30183,"date":"2020-09-18T14:10:18","date_gmt":"2020-09-18T18:10:18","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=30183"},"modified":"2020-09-28T15:26:26","modified_gmt":"2020-09-28T19:26:26","slug":"the-state-of-swiftui","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2020\/09\/18\/the-state-of-swiftui\/","title":{"rendered":"The State of SwiftUI"},"content":{"rendered":"<p><a href=\"https:\/\/steipete.com\/posts\/state-of-swiftui\/\">Peter Steinberger<\/a> (<a href=\"https:\/\/twitter.com\/steipete\/status\/1305543511647948802\">tweet<\/a>, <a href=\"https:\/\/twitter.com\/steipete\/status\/1305045661453365248\">2<\/a>, <a href=\"https:\/\/news.ycombinator.com\/item?id=24472063\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/steipete.com\/posts\/state-of-swiftui\/\"><p>Since then, there have been many betas, and we&rsquo;re nearing the end of the cycle, with the [Big Sur] GM expected in October. So it&rsquo;s time to look at Fruta again. And indeed, the SwiftUI team did a great job fixing the various issues: The toolbar is pretty reliable, the sidebar no longer jumps out, multiple windows works&#8230; however, <a href=\"https:\/\/twitter.com\/steipete\/status\/1305054121523916806?s=21\">views are still sometimes misaligned<\/a>, and it&rsquo;s still fairly easy to make it crash on both <a href=\"https:\/\/twitter.com\/steipete\/status\/1305051342596177921?s=21\">macOS (FB8682269)<\/a> and <a href=\"https:\/\/twitter.com\/steipete\/status\/1305052083989684224?s=21\">iOS 14b8 (FB8682290)<\/a>.<\/p><p>[&#8230;]<\/p><p>Most SwiftUI crashes are a result of either a diffing issue in AttributeGraph, or a bug with one of the bindings to the platform controls (AppKit or UIKit). Whenever you see <code>AG::Graph<\/code> in the stack trace, that&rsquo;s SwiftUI&rsquo;s AttributeGraph (written in C++), which takes over representing the view hierarchy and diffing. [&#8230;] Googling for this error reveals that there are <a href=\"https:\/\/github.com\/fermoya\/SwiftUIPager\/issues\/60\">a<\/a> <a href=\"https:\/\/developer.apple.com\/forums\/thread\/129171\">lot<\/a> <a href=\"https:\/\/stackoverflow.com\/questions\/58304009\/how-to-debug-precondition-failure-in-xcode\">of<\/a> <a href=\"https:\/\/www.reddit.com\/r\/SwiftUI\/comments\/fosrbf\/precondition_failure_invalid_input_index\/\">similar<\/a> <a href=\"https:\/\/twitter.com\/steipete\/status\/1258762457805455361\">problems<\/a>.<\/p>\n<p>[&#8230;]<\/p>\n<p>This isn&rsquo;t unique to Fruta. I&rsquo;ve been taking a look at <a href=\"https:\/\/twitter.com\/Dimillian\">@Dimillian&rsquo;s<\/a> RedditOS app, which is built with SwiftUI on macOS. He <a href=\"https:\/\/twitter.com\/Dimillian\/status\/1301802048824979456\">stopped development<\/a> because it&rsquo;s so slow that it&rsquo;s not shippable.<\/p><\/blockquote>\n\n<p>This is sad because stability and speed are supposed to be the selling points of Swift.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/frankreiff\/status\/1305509110520188928\">Frank Reiff<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/frankreiff\/status\/1305509110520188928\">\n<p>On the Mac, Swift UI is so far away from being practical that Apple might well have moved on to the next technology before it is.<\/p>\n<p>Mac apps need to be backwards compatible for at least 5 years, so if Swift UI is ready in 2022, it can&rsquo;t be used until 2027.<\/p>\n<\/blockquote>\n\n<p>It will be really interesting to see what happens with companies <a href=\"https:\/\/mjtsai.com\/blog\/2020\/07\/17\/omni-groups-new-licensing\/\">like Omni Group<\/a> who try to go all-in on SwiftUI. On the Mac side, it just doesn&rsquo;t make sense to me at this point, both because of the limitations with first responder and more advanced controls and because of the potential <a href=\"https:\/\/twitter.com\/willco007\/status\/1306996647818178561\">bugs<\/a> and performance issues. Making the easy stuff even easier doesn&rsquo;t seem worth possibly painting yourself into a corner. Also, roughly 1\/3 of my customers can&rsquo;t run SwiftUI apps at all.<\/p>\n\n<p><a href=\"https:\/\/twitter.com\/NathanBLawrence\/status\/1305593084777033729\">Nathan Lawrence<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/NathanBLawrence\/status\/1305593084777033729\"><p>I wouldn&rsquo;t use Fruta as a model for SwiftUI, even though Apple does.<\/p><p>It&rsquo;s not well structured, it has huge bugs, cruft from different approaches to certain problems that got abandoned months ago&#8230;it&rsquo;s not an illustration of the framework or its inner mechanics at their best.<\/p><p>I think what you learn when you build with SwiftUI at any kind of magnitude is that you&rsquo;re a little on your own. Many approaches that experts or instructors (including at friggin Stanford University!) offer are just plain nonfunctional or inefficient.<\/p><p>This is not because SwiftUI is broken &mdash; there are some decisions I disagree with, sure, and often those decisions can be a big enough problem the require some workarounds or extra coding of your own - but because it&rsquo;s poorly documented and explained. It is evolving so fast.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/getglyph.app\/blog\/3-building-glyph-a-year-with-swiftui\">Roshan Choxi<\/a>:<\/p>\n<blockquote cite=\"https:\/\/getglyph.app\/blog\/3-building-glyph-a-year-with-swiftui\"><p>For frontend designers and developers trying to deal with building UI that runs across dozens of devices, the goal of &ldquo;write once, run anywhere&rdquo; has been the panacea of UI development. If anyone had the motivation, talent, and platform control to achieve this goal it would be Apple. And I believe they have been largely successful with SwiftUI.<\/p>\n<p>[&#8230;]<\/p>\n<p>As great as SwiftUI does at universal UI code, it demonstrates that there is still a large amount of code that needs to be specific to the device because of the spectrum of different sizes, inputs, accessories, and hardware performance of different devices.<\/p><\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/stroughtonsmith\/status\/1306687912063447040\">Steve Troughton-Smith<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/stroughtonsmith\/status\/1306687912063447040\">\n<p>As a situational tool, SwiftUI is awesome. There&rsquo;s no way I&rsquo;d trust it to build an app directly, it&rsquo;s nowhere near reliable enough for that, but it&rsquo;s great for providing the content views for your UIKit view controllers and reducing so much manual layout code or storyboard work<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/DamienPetrilli\/status\/1306151920151785472\">Damien Petrilli<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/DamienPetrilli\/status\/1306151920151785472\">\n<p>My favorite SwiftUI bugs: when it crashes internally without knowing which line of code is involved so you have to troubleshoot, line by line, without any clue.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/thesamcoe\/status\/1306350596715282434\">Samuel Coe<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/thesamcoe\/status\/1306350596715282434\">\n<p>I can&rsquo;t bring myself to release this horribly buggy experience to users (thanks SwiftUI).<\/p>\n<p>My faith that Apple fixes this is low and I&rsquo;m feeling really let down that these keyboard-avoidance issues weren&rsquo;t fixed in Beta.<\/p>\n<p>This is a big lesson learned for me.<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\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<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<\/ul>\n\n<p id=\"the-state-of-swiftui-update-2020-09-28\">Update (2020-09-28): <a href=\"https:\/\/twitter.com\/thebuckley\/status\/1307065353156079617\">Michael Buckley<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/thebuckley\/status\/1307065353156079617\">\n<p>I feel pretty bad about all the time I spent trying to make SwiftUI work at Panic. The idea behind it is great, the actual design has some issues, but the implementation has been a nightmare to work with compared to AppKit or UIKit.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/twitter.com\/stroughtonsmith\/status\/1307361638799020034\">Steve Troughton-Smith<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/stroughtonsmith\/status\/1307361638799020034\">\n<p>My determination last year was that SwiftUI was a fantastic tool if used as a replacement for Interface Builder; spending a lot more time with it this year I think that&rsquo;s just as true today. Takes about the same amount of time to lay out a UI, but SwiftUI leaves you with <em>code<\/em><\/p>\n<p>Code is great because you can refactor it. Localize it. Switch container types by renaming them. Copy\/paste properties between views. Extract previously-static metrics to properties and tweak them dynamically layout-wide. Use ifs and ifdefs for conditional views &amp; layout<\/p>\n<p>Even if you&rsquo;re wrapping UIKit (\/AppKit), and don&rsquo;t trust SwiftUI for actual app logic (I definitely don&rsquo;t), I feel like moving from nibs &amp; storyboards to SwiftUI should be high on your priority list. I&rsquo;m genuinely surprised there isn&rsquo;t a SwiftUI replacement for launch storyboards<\/p>\n<\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2017\/10\/23\/why-work-without-a-nib\/\">Why Work Without a Nib?<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Peter Steinberger (tweet, 2, Hacker News): Since then, there have been many betas, and we&rsquo;re nearing the end of the cycle, with the [Big Sur] GM expected in October. So it&rsquo;s time to look at Fruta again. And indeed, the SwiftUI team did a great job fixing the various issues: The toolbar is pretty reliable, [&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-09-18T18:10:21Z","apple_news_api_id":"93e87e4e-205f-4078-af7d-20f134e62506","apple_news_api_modified_at":"2020-09-28T19:26:30Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAg==","apple_news_api_share_url":"https:\/\/apple.news\/Ak-h-TiBfQHivfSDxNOYlBg","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":[2],"tags":[131,326,164,31,1837,30,1891,71,901,1812],"class_list":["post-30183","post","type-post","status-publish","format-standard","hentry","category-technology","tag-bug","tag-c-plus-plus","tag-documentation","tag-ios","tag-ios-14","tag-mac","tag-macos-11-0","tag-programming","tag-swift-programming-language","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30183","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=30183"}],"version-history":[{"count":4,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30183\/revisions"}],"predecessor-version":[{"id":30270,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/30183\/revisions\/30270"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=30183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=30183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=30183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}