1. for in 与 oc 中的用法还是一样
var titesArr:[String] = ["I","AM","IS","WITH","L", "O", "V", "E", "I", "O", "S"]
for tempObj in titesArr {
print("测试:\(tempObj)")
print("<==========>")
}
Snip20200306_1.png输入如下:
2. enumerated() 正向快速遍历,还能拿到索引和指定的值。
var titesArr:[String] = ["I","AM","IS","WITH","L", "O", "V", "E", "I", "O", "S"]
for (index, text) in titesArr.enumerated() {
print("<------------------>")
print("index:\(index) <=> text:\(text)")
}
Snip20200306_2.png
3. reversed() 反向遍历获取对应的索引和值。
var titesArr:[String] = ["I","AM","IS","WITH","L", "O", "V", "E", "I", "O", "S"]
for (index, text) in titesArr.enumerated().reversed() {
print("<------------------>")
print("index:\(index) <=> text:\(text)")
}
Snip20200306_3.png
网友评论