Hi
At the moment i’m trying to build a Golf application, where one of the first steps is for the user to choose course and and combination ( 18 holes, 9 holes etc). Since most players play the same course over and over, i would like the application to start the picker, the same place as the selected last time.
What is the best way to do this ?? (It is only the first picker with the string array i want to save)
The simple picker system is build as below:
import SwiftUI
struct CourseView: View {
@Binding var klub:String
@State var klubber:[String] = ["Gilleleje Golf Klub", "Hillerød Golf Klub", "Hørsholm Golf Klub", "Rungsted Golf Klub", "Jokes"]
@Binding var valgtbane: String
@State var dataService = DataService()
@State var holeInfo:[HoleDefinition] = [HoleDefinition]()
var body: some View {
ZStack {
Color(red: 0.639, green: 0.847, blue: 0.792)
.ignoresSafeArea()
VStack {
Image("BG")
.resizable()
.aspectRatio(contentMode: .fit)
.cornerRadius( 20)
.padding(.all)
Spacer()
Text("Velkommen til BaneGuiden.DK")
.font(.largeTitle)
.fontWeight(.semibold)
.foregroundColor(Color(red: 0.506, green: 0.003, blue: 0.502))
.padding()
Spacer()
HStack{
Text("Vælg klub")
Spacer()
Picker("Hvilken Klub", selection: $klub) {
Text("<Intet Valgt>").tag("")
ForEach(klubber, id: \.self){
Text($0)
}
}
}.font(.title2)
HStack{
Text("Vælg kombination")
Spacer()
let baner:[CourseDefinition] = dataService.updateBaner(input1: klub)
Picker("Hvilken kombination", selection: $valgtbane) {
Text("<Intet Valgt>").tag("")
ForEach(baner, id: \.course){ item in
Text("\(item.course)")
}
}
//
}.font(.title2)
Spacer()
Text("Din valgte runde er: ")
Text(klub + " - " + valgtbane)
Spacer()
}.padding()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
CourseView(klub: Binding.constant(""), valgtbane: Binding.constant(""))
}
}