Use Variable outside function?

Hi,
Im tying to use a variable outside of a function, I've searched many different solitons and none seem to work

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {  
        let location = locations[0]  
        /  
        let Speed = location.speed * 2.236936284  
        SpeedLabel.text = "\(Speed)"  
    }  

I wish to use the variable "Speed" elsewhere in my program.. How can this be done?

Any help is appreciated

Thanks
Oliver

Hello Oliver,

Is assigning it to an external variable not an option? If not, could you elaborate on your case?

1 Like

Define the variable outside of the function.

C. Keith Ray

https://leanpub.com/wepntk <- buy my book?

http://agilesolutionspace.blogspot.com/

twitter: @ckeithray

http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf

1 Like

or have the function return the value.

C. Keith Ray

https://leanpub.com/wepntk <- buy my book?

http://agilesolutionspace.blogspot.com/

twitter: @ckeithray

http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf

var speed : Double = 0.0

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let location = locations[0]  

    speed = location.speed * 2.236936284  

    SpeedLabel.text = "\(speed)"  

}  

C. Keith Ray

https://leanpub.com/wepntk <- buy my book?

http://agilesolutionspace.blogspot.com/

twitter: @ckeithray

http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf