8 Quick Tips for Performant SwiftUI
I hope this helps!
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12.4, and Swift 5.7.2
Prerequisites:
You need to be able to code in Swift, perhaps using
Playgrounds and be able to use SwiftUI
Terminology
View: In SwiftUI a view is a protocol tht defines a piece of user interface and is a building block for creating UI in SwiftUI
Practices
Efficient Redraws
SwiftUI only redraws the differences (diffs) in the view hierarchy. This is inherently performant, but you can further optimize by ensuring that only necessary parts of your UI update in response to state changes.
Use of EquatableView
As you’ve detailed, using EquatableView can help avoid unnecessary redraws for complex views. By providing custom logic to determine if a view has changed, you can minimize the work SwiftUI has to do.
Avoiding Expensive Computations in body
The body property of a SwiftUI view can be called frequently. Avoid placing expensive computations…