-1
我有多个for循环,但我不知道如何反弹回到顶部循环每次为四个geojson记录我有单独的数组,地方,通过和拉特/长。如何控制多个for-in循环swift 2中的流量?
代码:
for aPlace in place {
print(aPlace)
for aPass in pass {
print(aPass)
for var (i, x) in zip(lat, long) {
print(i)
print(x)
//These must be in this order to load right at least from what I have seen thus far
var point = MGLPointAnnotation()
point.title = aPlace
point.subtitle = aPass
point.coordinate = CLLocationCoordinate2D(latitude: i, longitude: x)
print(point)
print(" ")
mapView.addAnnotation(point)
//after this the code jumps to pass type record2
break
}; break; continue
}
}
我有一些错误检查的有版画,以帮助我了解是怎么回事...
这是我所得到的打印出来......
North Shore Trailhead
passRecord1
48.066736
-123.835361
<MGLPointAnnotation: 0x7fa9b3a37630; title = "North Shore Trailhead"; subtitle = "passRecord1"; coordinate = 48.066736, -123.835361>
Lyre RiverTrailhead
passRecord1
48.066736
-123.835361
<MGLPointAnnotation: 0x7fa9b1c2aa40; title = "Lyre RiverTrailhead"; subtitle = "passRecord1"; coordinate = 48.066736, -123.835361>
在记录2中有不同的路径头位置是我想要的,所以这是可以的。之后,它只记录相同的passRecord#和相同的经度/纬度,然后将其报告给作为地图框标记的MGLAnnotation。
有没有更好的方法来做到这一点?我已经搜索了几个小时找到解释,这无济于事。
文档:
AppleDoc有标签说明的一部分,但我似乎无法得到这工作的。
,如果你在这个link看看嵌套的循环,它会显示哪些程序正在做......只是不知道如何解决它...
好了,所以当我这样做,我得到这样的结果...... 北岸路径起点 passRecord1 48.066736 -123.835361 48.091941 -123.801919 我想trailhead1,passRecord1,纬度/经度对点#1,并且它在注解形式通过所有记录 –
Staley
行打印,然后 trailhead2,passRecord2,纬度/ lon2,和annotation2例如等等,容易版本:迭代所有索引(从0到更小的计数元素),然后访问每个列表中适当的字段。 – user6569971
硬版本将通过某些fance map-filter-reduce调用同时迭代所有数组。你可以看看这里,如果有东西符合你的需求:http://useyourloaf.com/blog/swift-guide-to-map-filter-reduce/ – user6569971