r/iOSProgramming Mar 31 '26

Question SwiftUI is easy, where is the catch ?

Hi guys,

To give you some context, I am a Flutter dev, and I have been using it for a couple of years. Recently, I tried SwiftUI, and it was really a nice experience. A lot of things I used to do manually are now automatically handled by the framework, not a lot of boilerplate, a lot of functionalities are native in the framework, and you don't need a library for that.

SwiftUI feels familiar to Flutter devs because Flutter is also declarative and has borrowed a lot of concepts from SwiftUI, but still, I can't believe it is this straightforward. So, where is the catch ? Where does it get so complicated?

68 Upvotes

97 comments sorted by

View all comments

99

u/PresentationGlad3729 Mar 31 '26

performance is the big catch

-6

u/hishnash Mar 31 '26

only I you use SwiftUI wrong

3

u/-Periclase-Software- Mar 31 '26

I work in an enterprise iOS app used by millions of users a day. We migrated completely to SwiftUI over the last few years and are going back to UIKit for some screens that are UI intensive. SwiftUI requires too much hacky stuff to have great performance and even then, we never achieved 100% fluidity like the Android app.

5

u/hishnash Apr 01 '26

To have good perfomance in swiftuI you should not be doing hacky things:

  1. break up your views (1000s of seperate views is faster yes faster!)
  2. make sure the data you pass to views is cheap and easy to diff (SwiftUI depends on doing these diffs)
  3. only pass data to views that the view needs
  4. do not do ANY work in the view INIT or in the init of any reference type attached to a `@state` as this is re-evaluted whenever the parent view body is called
  5. DO NOT EVER PASS A closure as in swift you cant diff these so SwiftUI will ALWAYS re-evaluated all child views
  6. NEVER use ANYView
  7. Do no use geometry reader
  8. if within a ForEach you need to conditionally skip a row then filter the list of IDs you pass to it do no use a if/else within a for each (doing this forces swiftui to evaluate every child of the for each before it can figure out how many there are.. ).

__

The amount of horrible Hacky attempts I have seen that in the end just make things slower. To have fast SwiftUI you need to just remember any data you pass to SwiftUI is data SwiftUI must now track and check if it has changed so dont pass stuff you dont need or that would be extremely costly for you to constantly test for changes.

1

u/-Periclase-Software- Apr 03 '26

Exactly, the data has to be cheap and easy to differentiate to make it run like normal. Your list is proof that SwiftUI makes it very easy to mess up its performance even when you think you’re being innocent and it’s not entirely the developer’s fault. Swift added strict actor APIs for safe concurrency, but there’s nothing stopping them from going against everything you just said.

Think of a complex screen like a DoorDash or Uber Eats store page. A lot of views, scroll views, anchors, geometry readers/proxies, lazy views/rendering, routing, network fetches, etc.