mlem icon indicating copy to clipboard operation
mlem copied to clipboard

Review SwiftUI View initializers

Open boscojwho opened this issue 1 year ago • 0 comments

@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 Screenshot 2023-11-21 at 4 57 38 PM

Example Screenshot 2023-11-21 at 4 59 59 PM

boscojwho avatar Nov 22 '23 01:11 boscojwho