Iterating through an Enum in Swift 3.0
<p>I have a simple enum that I would like to iterate over. For this purpose, I've adopted Sequence and IteratorProtocol as shown in the code below. BTW, this can be copy/pasted to a Playground in Xcode 8.</p>

<pre><code>import UIKit

enum Sections: Int {
  case Section0 = 0
  case Section1
  case Section2
}

extension Sections : Sequence {
  func makeIterator() -&gt; SectionsGenerator {
    return SectionsGenerator()
  }

  struct SectionsGenerator: IteratorProtocol {
    var currentSection = 0

    mutating func next() -&gt; Sections? {
      guard let item = Sections(rawValue:currentSection) else {
        return nil
      }
      currentSection += 1
      return item
    }
  }
}

for section in Sections {
  print(section)
}
</code></pre>

<p>But the for-in loop generates the error message <strong>"Type 'Sections.Type' does not conform to protocol 'Sequence'"</strong>.
The protocol conformance is in my extension; so, what is wrong with this code?</p>

<p>I know there are other ways of doing this but I'd like to understand what's wrong with this approach.</p>

<p>Thanks.</p>