Ios 线程1:致命错误:for循环中的索引超出范围
在我的sampllat和sampllong中,数组包含40个双值,reflat long数组包含9个双值Ios 线程1:致命错误:for循环中的索引超出范围,ios,swift,Ios,Swift,在我的sampllat和sampllong中,数组包含40个双值,reflat long数组包含9个双值 您的问题在内部循环中,特别是在以下方面: for testing1 in (0...refLat.count).reversed() 这将比refLat中的值多迭代一次,您需要的是: for testing1 in (0..<refLat.count).reversed() }计数器从不重置0…refLat.count错误。应该是0..,这正是我建议人们永远不要写0..@Alexa
您的问题在内部循环中,特别是在以下方面:
for testing1 in (0...refLat.count).reversed()
这将比refLat中的值多迭代一次,您需要的是:
for testing1 in (0..<refLat.count).reversed()
}计数器从不重置0…refLat.count错误。应该是0..,这正是我建议人们永远不要写0..@Alexander的原因,值得一提的是,并非每个集合都必须从0索引开始和/或一直到count-1。ArraySlice还符合RandomAccessCollection
for testing1 in (0..<refLat.count).reversed()
// counterS will be generated and managed by the for loop
for counterS in (0..<sampLat.count) {
let coordinates = CLLocation(latitude:sampLat[counterS], longitude:sampLong[counterS])
// same for counterR
for counterR in (0..<refLat.count).reversed()
{
let coordinates2 = CLLocation(latitude:refLat[counterR], longitude:refLong[counterR])
let distanceInMeters = coordinates.distance(from: coordinates2)
// I will use string interpolation
print("distance found - \(distanceInMeters)")
print("Counter Reference - \(counterR)")
if distanceInMeters <= 50 {
print("crossed check point for - \(counterR)")
} else {
print("out of range")
}
print("---------------------------------------")
}
print("Counter Sample \(testing)")
print("******************************************")