You may have done what I did once.
There is a Confirm your submission stage which you may have missed?
Post
Replies
Boosts
Views
Activity
Found this solved my problem and is very informative to boot!
[https://youtu.be/poSmKJ_spts?si=z3r3gkDuQtkXtVmb)
Have done the neccessary Permission.
Also tested it outside of Playgrounds with TestFlight but no success.
Further investigated the above and now understand maybe the Code is incomplete?
Regarding the second version below which I prefer, I don’t yet see why it doesn’t work.
Also tried this without success.
class RequestLocationManager: NSObject, CLLocationManagerDelegate {
private let locationManager = CLLocationManager()
override init() {
super.init()
locationManager.delegate = self
}
func requestUserAuthorization() async throws {
locationManager.requestWhenInUseAuthorization()
}
}
I have worked it out and in doing so have dispelled the myth I was spreading unknowingly!
I managed to move all the functions to one View.
I am mystified because I am sure Swift wasn’t letting me when I first started building my app (Unfortunately too long ago to know why).
The only difference now is this new View has very little viewable content.
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
A Resulting Card / Record
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
}
Part of the Form
import CoreLocation not showing in Location Helper but is there.
import MapKit not showing in Map View but is there.
import SwiftUI not showing in This View passes the Marker Latitude… but is there.
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”?
EDIT: Working except for User’s Location (See below and ignore above)
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()
}
}
Did you see the encryption question?
You have three choices. I selected none of the above and it worked.
Having said all that I am not really sure if this is your problem but thought it worth a mention.