Group Group Group Group Group Group Group Group Group

Initializer unused

Any help on this?

Result of ‘ForEach<Data, ID, Content>’ initializer is unused

func descriptionItem(myFrom: Int, myTo: Int) {
ForEach(myFrom …< myTo) { item in
Button(action: {
self.myDetail = self.mySites[item]
self.saveData()
// self.showAlert = true
}) {
Text(self.mySites[item]).modifier(ButtonModifier())
}

    }
}

Thanks I did this:
func descriptionItem(myFrom: Int, myTo: Int) -> some View{
and it works now.

Hi @flmcl, try adding a return type to your function.

Best,
Gina

1 Like

Your syntax for calling the initializer is incorrect. Change:

TestStruct.init(base: data_base, date: data_date, rates: data_rates)
to:

let someVar = TestStruct(base: data_base, date: data_date, rates: data_rates)
And the error with:

testLabel.text = TestStruct().base
is that you are trying to access the base property on a newly created TestStruct instance but you have no init on your TestStruct with no parameters.

You need to create TestStruct by passing all of the required arguments but that seems pointless since all you want is its base and you need the base to create the instance to begin with.

1 Like