I am trying to pass data from my child view to the parent view. I also pass some data from the parent to the child.
struct Parent: View {
...
var body: some View {
OneColumnList(changeStage: changeStage, icons: icons, options: options)
...
struct Child: View {
var changeStage: (Int) -> ()
var icons: [String]
var options: [String]
init(icons: [String], options: [String]) {
self.icons = icons
self.options = options
}
...
I currently get this error on the child:
Return from initializer without initializing all stored properties
I guess I need to initialise changeStage
, but I can’t work out how to do it. I’d appreciate any help!
2
Answers
changeState according to its type should be a completion block, that receives one Int argument and returns Void. Try adding this to the init:
I think you need to enhance your init method of the
Child
.E.g.
Then you can handle the state changes in your
Parent
, like for example