Ios 无法调用类型为';双倍';具有类型为';(范围<;双>;)&x27;

Ios 无法调用类型为';双倍';具有类型为';(范围<;双>;)&x27;,ios,swift,swift4,Ios,Swift,Swift4,我在这里遇到了这个错误(无法使用类型为“(范围)”的参数列表调用类型为“Double”的初始值设定项) 汽车是我可以下载的汽车,如果我真的可以下载这些汽车,回答会选择,最后回答。汽车是我将要下载的汽车。现在我想在一个过滤器中订购那些从最近的到最公平的汽车,但我的问题是,我需要从我的位置到一个具有外部功能的X汽车的距离值 func distance(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) -> CLLocationD

我在这里遇到了这个错误(无法使用类型为“(范围)”的参数列表调用类型为“Double”的初始值设定项)

汽车是我可以下载的汽车,如果我真的可以下载这些汽车,回答会选择,最后回答。汽车是我将要下载的汽车。现在我想在一个过滤器中订购那些从最近的到最公平的汽车,但我的问题是,我需要从我的位置到一个具有外部功能的X汽车的距离值

func distance(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) -> CLLocationDistance {
        let from = CLLocation(latitude: from.latitude, longitude: from.longitude)
        let to = CLLocation(latitude: to.latitude, longitude: to.longitude)

        return from.distance(from: to)

    }


    func didSelectt(car:Car) {

        guard let coordinates = car.location  else {
            return
        }
        self.destination = coordinates

        // update distance
        if currentLocation != nil {
            let dist = distance(from: currentLocation!, to: coordinates)
        }
    }        

循环中
in
参数的类型必须是
Int
的范围。此外,您不能将范围转换为单一类型,如
Double

在序列上迭代!=<代码>整数您需要
步幅

let distance = 25.0

for dista in stride(from:0.0, to: distance, by: 1.0) {
    print(dista)
}

你认为双重(0..我想做这样的事情“车内距离”但我得到的错误类型“Double”不符合协议“Sequence”,因此我尝试使用
汽车进行更改。距离
是一个单一的数字。你到底想迭代什么?是的,它应该抛出一个错误。在这里,你正在将范围转换为Double(这肯定会失败)和Double不符合顺序协议。我更新了问题我更新了问题,如果你能检查的话
func distance(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) -> CLLocationDistance {
        let from = CLLocation(latitude: from.latitude, longitude: from.longitude)
        let to = CLLocation(latitude: to.latitude, longitude: to.longitude)

        return from.distance(from: to)

    }


    func didSelectt(car:Car) {

        guard let coordinates = car.location  else {
            return
        }
        self.destination = coordinates

        // update distance
        if currentLocation != nil {
            let dist = distance(from: currentLocation!, to: coordinates)
        }
    }        
let distance = 25.0

for dista in stride(from:0.0, to: distance, by: 1.0) {
    print(dista)
}