Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Access struct value.

dickthedevdickthedev Posts: 214Registered Users @ @
edited May 24 in iOS SDK Development
Hello, I have a few functions need to access some common variables, but I was told using global variable is poor practice, I should use struct instead. So here I am.

I difined a Location struct.
struct Location {
    let latitude: Double
    let longitude: Double
}

Instantiated the struct here to obtai the user's current location
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

        let locValue: CLLocationCoordinate2D = manager.location!.coordinate

        // Here I put locValue into the struct Location so that other functions can access it
        let currentLocation = Location(latitude: locValue.latitude, longitude: locValue.longitude)
        

    }

later on in the code in a function, I need to access the latitude and longitude from the struct Location
How can I access them? Thanks
Sign In or Register to comment.