UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Views in Swift

Forums > SwiftUI

I'm new to Swift but have been through many of the Hacking with Swift Tutorials. I am writing a scoring program that may contain between 4 and 9 teams. I need to enter the number of teams (I can do that) and enter the names of each team member, 4 to a team. (I can do that.) However, I am doing it the hard way by just repeating the following 9 times and just chnaging the indexes and the Team number.
VStack { HStack { Text("Team 1") TextField("Front Nine:", text: $front9[0]) TextField("Back Nine:", text: $back9[0]) Text("Sum") Spacer() } VStack { TextField("Name", text: $name1[0]) TextField("Name", text: $name1[1]) TextField("Name", text: $name1[2]) TextField("Name", text: $name1[3]) } } It seems there should be a wasy to dislay the above on a screen however once for each team e and appropriately increment the indexes, team number, name, front9 and back9 indexs. After all the teams are created, I want to display all of them on a scrollable screen.

It seems that I should be able to create either a struct or class that has the basic layout as above and then just iterate the number of teams. I've tried a lot of things but nothing works.

Any help or suggestion are appreciated. Thanks.

3      

Could you approach this by seperating the name of the team and slots for 4 members into its own view. Then when the user wants to add a new team, you present that view as a popup sheet. Capturing the Team info and members into its own

This sort of pattern is demo'd very well in Project 11, Bookworm of the 100 days of Swift UI course.

I think this is a really nice example project for many app's, it incorporates CoreData for storage and the basics of adding/removing etc

4      

Thank you. I've been through a number of the tutorials but not the Bookworn one. I'll give that a try today.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.