0

I have SwiftUI view that has some @State properties like isSelected I would like to init state of this variable via constructor.

Here is sample code

 @State var isSelected : Bool = false

    init(user: User, isSelected: Bool, onChange: @escaping (Bool) -> Void = { _ in }) {
        self.user = user
        self.onChange = onChange

        self.isSelected = isSelected
    }

But unfortunately this does not work and View inits with isSelected set to false.

Why is it this way? How could I solve this issue?

Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143

0 Answers0