想要swift实现for循环,且带index的
搜:
swift for with index
参考:
用:
headerCharArr:[String] for (index, singleHeaderChar) in headerCharArr.enumerate() { print("[\(index)] singleHeaderChar=\(singleHeaderChar)")
即可。
[总结]
swift中,for循环带索引可以写成:
for (curIndex, eachItem) in itemList.enumerate() { print("curIndex=\(curIndex),eachItem=\(eachItem)") }
即可
转载请注明:在路上 » [已解决]swift中for循环中加上index索引