mlem
mlem copied to clipboard
Review SwiftUI View initializers
@State
/@StateObject
variables should use .init(wrappedValue: ), but in some views we are either not using this initializer, or perform logic outside of it before passing a value into the @autoclosure/Value.
- State that only needs to be calculated/initialized once over the view's lifetime needs to use/be calculated in
.init(wrappedValue:)
- I haven't inspected this in Instruments yet, but it seems like in some places we are preventing SwiftUI from doing its performance optimizations or preventing it from knowing a value only needs to be instantiated once over its lifetime.
Example
Example