I have an array:
let individualScores = [75, 43, 103, 87, 12]
And I iterate like this:
for score in individualScores {
}
However, is there a way to declare the object type explicitly? I think it would come in handy later w/ custom objects, or other reasons. Something like:
for Integer score in individualScores {
}
When you type a variable, you do:
var score: Int
And you do the same in a loop:
for score: Int in individualScores {
}
It seems to be pretty consistent in that regard.
yes its possible
let individualScores:Int[] = [75, 43, 103, 87, 12]
for score:Int in individualScores {
}
Yes. You can explicitly specify the type if you wish.
let individualScores = [75, 43, 103, 87, 12]
for score: Int in individualScores {
println(score)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With