Post

Replies

Boosts

Views

Activity

Reply to Guidance Needed: TextField, Import UI & Other Errors
Hello again I hope this explanation helps you better (My explanations of the Code may not be using the correct terminology but they are how I understand them (Layman’s Terms)). @Published var firstCardNumber = "1" // Form Inputs need to be made Observable (Cards:) | struct FormBuilder: View { @StateObject var cards = Cards() // Attaching variables in Form to an ObservableObject (Cards:) | TextField("Card Number:", text: $cards.firstCardNumber) // Creating field in the Form and attaching to Cards: | Text("✅ Okay ✅") .font(.headline) .foregroundColor(.red) .frame(maxWidth: .infinity, alignment: .center) .padding() }.sheet(isPresented: $submit) { FormResultView(cards: cards) // Passing Form Data to another View (Form Result View) } | struct FormResultView: View { @ObservedObject var cards = Cards() // Making the Form Inputs able to be seen in this View var body: some View { | Section { VStack { Text("Card Number: \(cards.firstCardNumber)") // The Form Field Input appears here
Oct ’23
Reply to Guidance Needed: TextField, Import UI & Other Errors
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 }
Oct ’23
Reply to Is this bad practice?
am a “newbie” to Coding and Swift. To better understand the Code I have started breaking it up into chunks and formatting as per my example below. My questions are 1) is “Is this bad practice”? 2) “Is it likely to lead to problems later on”?
Feb ’23
Reply to Displaying two sets of GPS Coordinates on a map
Found this is working for me except for displaying the user’s location. Can someone tell me what I am doing wrong please 🙏 Positions View import MapKit struct Positions: Identifiable {     let id = UUID()     let name: String     let latitude: Double     let longitude: Double     var coordinate: CLLocationCoordinate2D {         CLLocationCoordinate2D(latitude: latitude, longitude: longitude)     } } Map View import MapKit let thisCardPositionLatitude = -27.907625 let thisCardPositionLongitude = 152.680835 let nextCardPositionLatitude = -27.908190 let nextCardPositionLongitude = 152.679676     struct MapView: View {         @State private var region = MKCoordinateRegion(             center: CLLocationCoordinate2D(                 latitude: thisCardPositionLatitude,                 longitude: thisCardPositionLongitude),             span: MKCoordinateSpan(                 latitudeDelta: 0.00001,                 longitudeDelta: 0.00001)         )         private let places = [             Positions(name: "This Card Position", latitude: thisCardPositionLatitude, longitude: thisCardPositionLongitude),             Positions(name: "Next Card Position", latitude: nextCardPositionLatitude, longitude: nextCardPositionLongitude)         ]         var body: some View {             Map(coordinateRegion: $region,                 showsUserLocation: true,                 userTrackingMode: .constant(.follow),                 annotationItems: places){ place in                 MapMarker(coordinate: place.coordinate,tint: Color.accentColor)             }                 .edgesIgnoringSafeArea(.all)         }     }     struct MapView_Previews: PreviewProvider {         static var previews: some View {             MapView()         }     }
Feb ’23