Been thinking about what I've learned after working exclusively with SwiftUI for 6 months now (I really need to get a blog going) and thought I'd share some of them here 🧵
You need to throw everything you know about App/UIKit out for a while. SwiftUI is not only declarative in its syntax, but it’s also an abstraction where platform, SDK and context ultimately decides what will happen. Never take anything literally until you’ve tested it.
There are lots of implications to your apps behaviour and appearance happening under the hood all the time. One big culprit can be parameter defaults. Always check the function signatures in the header before using them.
A SwiftUI app consists of hundreds or thousands of views that can refresh and recreate constantly. Align your view and model design to limit the performance impact. Never do work in View inits, and compartmentalise subviews and their states. And always keep an eye on the CPU %.
SwiftUI didn't really become viable for production until version 2 (iOS 14/Big Sur). If you try to ship the older version, you will be spending more time fighting the framework than shipping features.
ObservableObject is awesome! But did you know that once you start subclassing it, all the functionality breaks down? stackoverflow.com/questions/5761…
Apple sample projects are not gospel. They are shallow showcases that’s meant to highlight certain features like widgets, app clips, platform interoperability and so on. The performance, UX, and sometimes even code practices should not be attributed to SwiftUI itself.
Very often your bugs will be originating from your data model. SwiftUI relies heavily on good data structures, and using it for real world apps with complex models and actions isn’t possible until you master Combine. Practical Combine by @DonnyWals is a great resource.
You will see conditional modifiers (applyIf) and AnyView used everywhere in tutorials and Stack Overflow, but they are huge code smells that come with big performance implications. Unless you really know how they work, don’t use them.
SwiftUI limitations are not actual limitations. Where the capabilities of SwiftUI ends, you are one short bridge away from letting App/UIKit handle the final stretch.
Lastly, don't trust the naysayers. I almost quit SwiftUI several times after seeing much more experienced devs dismiss it for being broken and incomplete. If someone doesn't have the credibility and experience with SwiftUI, chances are they don't know what they are talking about.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Oskar Groth

Oskar Groth Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!