I need to optimize my SwiftUI code, and views conforming to Equatable seem to a good way forward. However, I have some questions, that could be also an interest of others.
- View can conform to Equatable, and NOT encapsulated in
EquatableViewnor.equatable()view modifier, and modern SwiftUI implementations still can use theEquatablefunctionality, right? - When view contains
@ObservedObjector@EnvironmentObject, thenstatic func == (...)have to handle the changes of the observed objects, otherwise the view is not updated after the observed object published change. At least this is my experience. Correct? - Does view, that is
Equatable, need to care about equality of its subviews? I hope no. I hope that view can evaluate equality only based on properties available to it, and SwiftUI takes responsibility for its subviews. I. e.: Even when some view returns true on ==, but something changes in its subview (detail hidden to the view), SwiftUI is able to recognize the change and takes appropriate actions. Correct? - When view returns true on equality check (==), but some environment value changes (not visible to the view), the view still reflects the change. Correct?
- When the observed object conforms to
Equatable, it is being used by SwiftUI. For what purpose? In most (if not all) cases,lhsandrhsare the same instance, so == returns true.