On File 1, I have 3 strings, all which save with the UserDefaults.standard.set line. On the same file / page, I have a text box that displays the threes strings. When I close the app and reopen, the same values are displayed. However, when I call the strings on File 2 / p age 2, the values do not display.
An explanation and code would be helpful. I am new to swift.
Code:
//------file 1----------
@State var text: String = UserDefaults.standard.string(forKey: "TEXT_key") ?? ""
@State var inputText: String = ""
static var InText: String = UserDefaults.standard.string(forKey: "InText_key") ?? ""
TextField("Enter Text", text: $inputText)
text = inputText
File1.InText = text
Text("Saved Text: \(text)").lineLimit(3)
// Does display the text after app closed and reopened
//--------FILE 2--------
if let longitude = Double(File1.text), let latitude = Double(File1.text2) {
let location = CLLocation(latitude: longitude, longitude: latitude)
// When I enter the values again on file1, it updates. but when I close and reopen, nothing shows.
Excuse any syntax errors
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am new to swift and I am trying to use variables in the CLLocation. When I include the variables it says I need a double. How could I go about this?
My code:
//File 1
static var long: String = UserDefaults.standard.string(forKey: "long_key") ?? ""
static var lat: String = UserDefaults.standard.string(forKey: "lat_key") ?? ""
//File 2
let longitude = File1.long
let latitude = File2.lat
let location = CLLocation(latitude: longitude, longitude: latitude)