Reputation: 13
I am following an online class but my professor is using a different version of Xcode. I have version 7.2.1. It asked me to put parentheses after arr in the second line, but when I do, it says "Type "()" does not conform to protocol SequenceType
. I don't know how to fix it. Thanks.
var arr = {1; 2; 3; 4}
for i in arr() {
print(i)
}
Upvotes: 0
Views: 1864
Reputation: 15025
Another way to write the same way is using below:-
half-open range operator (..<)
let arr = [1, 2, 3, 4]
for i in 0..<arr.count
{
print(arr[i])
}
closed range operator (...)
let arr = [1, 2, 3, 4]
for i in 0...arr.count-1
{
print(arr[i])
}
Upvotes: 0
Reputation: 108
Your array declaration needs to use brackets and commas.
var arr = [1, 2, 3, 4]
for i in arr {
print(i)
}
Upvotes: 2