CLLocation distanceFromLocation (in Swift?)

Can anyone help me convert the following Objective-C statement to Swift?

CLLocationDistance distance = [fromLocation distanceFromLocation:toLocation];

      

I know it should be easy to do. I am new to iOS programming and any help would be greatly appreciated.

Thank!: -)

+7


source to share


2 answers


let distance = fromLocation.distanceFromLocation(toLocation)

      

New syntax:



let distance = aLocation.distance(from: anotherLocation)

      

+20


source


func distanceFromLocation(_ location: CLLocation!) -> CLLocationDistance

      

Returns the distance (in meters) from the location of the receivers to the specified location.



More details here https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/index.html#//apple_ref/occ/instm/CLLocation/distanceFromLocation :

+4


source







All Articles