I'm following the steps in this article to improve SwiftUI performance with custom diffing. For now, I'm just returning true
in ==
:
struct MyView: View, Equatable {
@ObservedObject var model: DataModel
static func == (lhs: Self, rhs: Self) -> Bool {
return true
}
var body: some View { ... lots of stuff ... }
}
I'm using .equatable()
to wrap MyView
in EquatableView
where it's used.
However in the SwiftUI instrument, I still see the entire view rebuilt whenever DataModel
changes. And the debugger confirms that body
is called. ==
is also called.
It would seem that customizing diffing can't be used with @ObservedObject
. When I remove the @ObservedObject
, body
isn't called. But without @ObservedObject
, I can't bind the UI within my view to my data model (similar issue for @EnvironmentObject
).
Anyone know how to accomplish this? thanks!