在Swift中迭代一个带有显式对象类型的数组

Log*_*gan 27 swift

我有一个数组:

let individualScores = [75, 43, 103, 87, 12]
Run Code Online (Sandbox Code Playgroud)

我这样迭代:

for score in individualScores {

}
Run Code Online (Sandbox Code Playgroud)

但是,有没有办法明确声明对象类型?我认为它会在以后用自定义对象或其他原因派上用场.就像是:

for Integer score in individualScores {

}
Run Code Online (Sandbox Code Playgroud)

Ale*_*yne 49

键入变量时,您执行以下操作:

var score: Int
Run Code Online (Sandbox Code Playgroud)

你在循环中做同样的事情:

for score: Int in individualScores {

}
Run Code Online (Sandbox Code Playgroud)

在这方面似乎非常一致.


Sam*_*Sam 5

是的可能

let individualScores:Int[] = [75, 43, 103, 87, 12]

for score:Int in individualScores {

}
Run Code Online (Sandbox Code Playgroud)