对Range使用for-in
for number in 1..<10{
number
}
对string.characters使用for-in
for c in "hello".characters{
c
}
对Array使用for-in
var vowels = ["a","s","d","f"]
for vowel in vowels{
vowel
}
for (i,vowel) in vowels.enumerate(){
i
vowel
}
对Dictionary使用for-in
var dict = [1:"A",2:"B",3:"C"]
for key in dict.keys{
key
}
for value in dict.values{
value
}
for (key,value) in dict{
key
value
}
对set使用for-in
var set = Set(vowels)
for vowel in set {
vowel
}
//奇奇怪怪的类型
"hello".characters
vowels.enumerate()
dict.keys
//可迭代