Group Group Group Group Group Group Group Group Group

Duplicate HStack

I’m new to iOS but have been through creating the Bulls Eye app. Now I’m trying to build my own app and take to heart the DRY concept. So what I want to do is have something like the coding below (not flushed out) but not have have to repeat the HStack for up to 10 Teams. I envision a Button that asks for how many Teams and then create that many HStacks with the frontNine, backNine arrays get incremented. Any help is appreciated. By the way, what I have below works.
VStack {
HStack {
Text("Front nine score: ")
TextField(“Front Nine”, text: $frontNine[0])
Text("Back nine score: ")
TextField(“Back Nine”, text: $backNine[0])
Text("Total: " + “(sum(front9: frontNine[0], back9: backNine[0]))”)
}
HStack {
Text("Front nine score: ")
TextField(“Front Nine”, text: $frontNine[1])
Text("Back nine score: ")
TextField(“Back Nine”, text: $backNine[1])
Text("Total: " + “(sum(front9: frontNine[1], back9: backNine[1]))”)
}
}

Hi @Tessa,
There is another element called a group, this is used to allow you to overcome the 9/10 elements issue.

So you can have an outer loop that creates anything from 1 to 10 teams, and each team is the group that contains the UI data. So this way you do not have to deal with arrays and complicated data handling. The tam UI can be a component that is self contained and when you create 1-n components, each will have their own source of truth.

cheers,

Thank you. I’ll research Group Views and I’ll give that a try. My problem with Swift is not writing functions to do the tasks I need done. It is displaying the results. In a pseudo code style, I want to
View 1
How many teams?
View 2
Enter the names of the players.
Repeat View 2 for the number of teams from View 1.
View 3
A list of all the teams.
I can do View 1 and 2. What I can’t seem to figure out is how to iterate over the, say, 8 teams and produce
Team 1 Score 1: ____ Score 2: ____ Total: _____
Name 1
Name 2
Name 3
Name 4
Team 2 Score 1: ____ Score 2: ____ Total: _____
Name 1
Name 2
Name 3
Name 4

Hi @Tessa,
You can achieve that in one of two ways,

  1. Have a wizard like set of screens that go through “step #x of n” and have the elements for each page and two buttons that offer you to go back or next, unless it is the first screen that has cancel and next and the last screen that has back and done.

  2. Have a form or a flowing list of elements that are in groups and the visibility of these groups can be set in state variables that will show or hide these groups as you continue through these questions.

cheers,

Thank you. Not sure how to code what you suggest but I have a general idea of a plan.