Type Int does not conform to protocol sequence

Toby V. picture Toby V. · Feb 6, 2017 · Viewed 47.6k times · Source

I have the following code in Swift 3:

var numbers = [1,2,1]
for number in numbers.count - 1 { // error
    if numbers[number]  < numbers[number + 1] {
        print(number)
    }
}

I am checking if the value on the index [number] is always higher than the value on the index [number + 1]. I am getting an error:

Type Int does not conform to protocol sequence

Any idea?

Answer

mqz.kim picture mqz.kim · Feb 6, 2017

It may be swift. You can use this iteration.

for number in 0..<(numbers.count-1)