如何通过数组和LT元素循环; UnsafeMutablePointer>在斯威夫特 [英] how to loop through elements of array of <UnsafeMutablePointer> in Swift

查看:159
本文介绍了如何通过数组和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)")
}

这篇关于如何通过数组和LT元素循环; UnsafeMutablePointer>在斯威夫特的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆