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