You are missing return type in your method header.
func calculateDistance(location: CLLocation) -> CLLocationDistance {
Seemingly my answer looks as an inferior duplicate, so some addition.
Functions (including methods, in this case) declared without return types are called as void function, because:
func f() {
//...
}
is equivalent to:
func f() -> Void {
//...
}
Usually, you cannot return any value from such void functions.
But, in Swift, you can return only one value (I'm not sure it can be called as "value"), "void value" represented by ()
.
func f() {
//...
return () //<- No error here.
}
Now, you can understand the meaning of the error message:
unexpected non-void return value in void function
You need to change the return value or else change the return type Void
to some other type.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…