草庐IT

doIteration

全部标签

快速函数迭代可能反转的数组

我想创建一个函数来遍历数组(或集合或序列)。然后,我将使用数组和数组的反转版本调用该函数(但效率很高:无需创建新数组来保存反转版本)。如果我这样做:funcdoIteration(points:[CGPoint]){forpinpoints{doSomethingWithPoint(p)}//IalsoneedrandomaccesstopointsdoSomethingElseWithPoint(points[points.count-2])//ignoreobviousindexerror}如果我有这个:letpoints:[CGPoint]=whatever我可以做到这一点:do