如何通过数组和LT元素循环; UnsafeMutablePointer>在斯威夫特

问题描述:

我是新来的斯威夫特,通过MKMapPoints这是我从一个MKPolygon获得通过调用myPoly.points()数组想循环。
然而,我被困在如何遍历指针的C数组的每个元素。

I am new to Swift and wanted to loop through an array of MKMapPoints which I get from an MKPolygon by calling myPoly.points(). However, I am stuck as to how to loop through every element of the C-Array of pointers.

 for element in myPointsArray {} 

不工作,我不知道如何确定这种斯威夫特数组的元素的数量。有任何想法吗?感谢您的帮助!

does not work and I don't know how determine the number of elements of this kind of array in Swift. Any ideas? Thanks for your help!

UnsafeBufferPointer presents不安全的指针和计数作为一个集合,所以你可以为..在过吧,下标是安全的,它传递给上工作的集合算法等:

UnsafeBufferPointer presents an unsafe pointer and a count as a collection so you can for..in over it, subscript it safely, pass it to algorithms that work on collections etc:

for point in UnsafeBufferPointer(start: poly.points(), count: poly.pointCount) {
    println("\(point.x),\(point.y)")
}