Hello, firstly I also am relatively new to SwiftUI and am working on my first app.
Secondly I don’t actually know the answer to your question and certainly don’t want to confuse you but wanted to show you another way to approach Form Filling. This way works well but if it doesn’t suit your needs I certainly won’t be offended.
The code I have supplied is by no way complete but I have tried to give you the necessary chunks for you to hopefully get an idea.
I will also attach a screenshot to show the resulting Form.
I hope this helps in some way.
class Cards: ObservableObject {
@Published var firstCardNumber = "1"
@Published var firstCardWords = gameArray [1]
@Published var firstCardLatitude = gameArray [2]
@Published var firstCardLongitude = gameArray [3]
@Published var firstCardFirstWordClue = gameArray [4]
@Published var firstCardSecondWordClue = gameArray [5]
@Published var firstCardThirdWordClue = gameArray [6]
@Published var firstCardAnswerClue = ""
@Published var firstCardFirstLetters = ""
@Published var firstCardSecondLetters = ""
@Published var firstCardThirdLetters = ""
@Published var firstCardFirstWord = ""
@Published var firstCardSecondWord = ""
@Published var firstCardThirdWord = ""
@Published var firstCardLettersResult = []
@Published var firstCardWordClueResult = []
@Published var secondCardNumber = "2"
etc.
@State private var submit = false
@State private var count = 0
@StateObject var cards = Cards()
@State var firstCards = (String)()
@State var firstCardsJoin = (String)()
@State var secondCards = (String)()
@State var secondCardsJoin = (String)()
etc.
VStack (alignment: .center){
Text("Game Form")
.font(.headline)
.bold()
.frame(maxWidth: .infinity, alignment: .center)
.onAppear(perform: {
count = 1
firstCardsJoined ()
})
}
Section {
TextField("Card Number:", text: $cards.firstCardNumber)
.multilineTextAlignment(.center)
SecureField("full-stops.between.words", text: $cards.firstCardWords)
.textCase(.lowercase)
.keyboardType(.alphabet)
.disableAutocorrection(true)
.textInputAutocapitalization(.never)
.multilineTextAlignment(.center)
TextField("Latitude (North-South)", text: $cards.firstCardLatitude)
.multilineTextAlignment(.center)
TextField("Longitude (East-West)", text: $cards.firstCardLongitude)
.multilineTextAlignment(.center)
TextField("First Word Clue. Maximum Charaters : 80", text: $cards.firstCardFirstWordClue)
.multilineTextAlignment(.center)
TextField("Second Word Clue. Maximum Charaters : 80", text: $cards.firstCardSecondWordClue)
.multilineTextAlignment(.center)
TextField("Third Word Clue. Maximum Charaters : 80", text: $cards.firstCardThirdWordClue)
.multilineTextAlignment(.center)
}
Section {
TextField("Card Number:", text: $cards.secondCardNumber)
.multilineTextAlignment(.center)
SecureField("full-stops.between.words", text: $cards.secondCardWords)
.textCase(.lowercase)
.keyboardType(.alphabet)
.disableAutocorrection(true)
.textInputAutocapitalization(.never)
.multilineTextAlignment(.center)
TextField("Latitude (North-South)", text: $cards.secondCardLatitude)
.multilineTextAlignment(.center)
TextField("Longitude (East-West)", text: $cards.secondCardLongitude)
.multilineTextAlignment(.center)
TextField("First Word Clue. Maximum Charaters : 80", text: $cards.secondCardFirstWordClue)
.multilineTextAlignment(.center)
TextField("Second Word Clue Maximum Charaters : 80", text: $cards.secondCardSecondWordClue)
.multilineTextAlignment(.center)
TextField("Third Word Clue Maximum Charaters : 80", text: $cards.secondCardThirdWordClue)
.multilineTextAlignment(.center)
}
etc.
self.submit.toggle()
if count == 1 {
firstCardsJoined()
}
}) {
Text("✅ Okay ✅")
.font(.headline)
.foregroundColor(.red)
.frame(maxWidth: .infinity, alignment: .center)
.padding()
}.sheet(isPresented: $submit) {
FormResultView(cards: cards)
}
}
}
func firstCardsJoined () {
firstCardsJoin =
cards.firstCardNumber + "," + cards.firstCardWords + "," +
cards.firstCardLatitude + "," + cards.firstCardLongitude + "," +
cards.firstCardFirstWordClue + "," + cards.firstCardSecondWordClue + "," +
cards.firstCardThirdWordClue + ",,,,"
firstCardsLettersJoined()
}
func firstCardsLettersJoined () {
firstCards = firstCardsJoin
secondCardsJoined()
}
func secondCardsJoined () {
secondCardsJoin =
cards.secondCardNumber + "," + cards.secondCardWords + "," +
cards.secondCardLatitude + "," + cards.secondCardLongitude + "," +
cards.secondCardFirstWordClue + "," + cards.secondCardSecondWordClue + "," +
cards.secondCardThirdWordClue + ",,,,"
secondCardsLettersJoined()
}
func secondCardsLettersJoined () {
secondCards = secondCardsJoin
thirdCardsJoined()
}
etc.
cards.sharedFile = firstCards + "," + secondCards + "," + thirdCards + "," + fourthCards + "," + fifthCards + "," + sixthCards
}
Array Builder
@ObservedObject var cards = Cards()
@State var firstCards = (String)()
@State var firstCardsJoin = (String)()
@State var firstCardLetters = (String)()
@State var secondCards = (String)()
etc.
func sixthCardsLettersJoined () {
sixthCardLetters =
cards.sixthCardFirstLetters + "," + cards.sixthCardSecondLetters + "," +
etc.
func allCardsJoined () {
formData = firstCards + "," + secondCards + "," + thirdCards + "," + fourthCards + "," + fifthCards + "," + sixthCards
formArray = formData.components(separatedBy: ",")
gameArray = formArray
}