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)
Welcome.
You have to convert your strings to Double. As conversion may fail (if File1.long is "" for instance), you need to use if let to test for nil:
if let longitude = Double(File1.long), let latitude = Double(File2.lat) {
let location = CLLocation(latitude: longitude, longitude: latitude)
// Continue code
}