title: How can I use a Swift enum as a Dictionary key? (Conforming to Equatable)
body: <p>I've defined an enum to represent a selection of a "station"; stations are defined by a unique positive integer, so I've created the following enum to allow negative values to represent special selections:</p>
  
  <pre><code>enum StationSelector : Printable {
      case Nearest
      case LastShown
      case List
      case Specific(Int)
  
      func toInt() -&gt; Int {
          switch self {
          case .Nearest:
              return -1
          case .LastShown:
              return -2
          case .List:
              return -3
          case .Specific(let stationNum):
              return stationNum
          }
      }
  
      static func fromInt(value:Int) -&gt; StationSelector? {
          if value &gt; 0 {
              return StationSelector.Specific(value)
          }
          switch value {
          case -1:
              return StationSelector.Nearest
          case -2:
              return StationSelector.LastShown
          case -3:
              return StationSelector.List
          default:
              return nil
          }
      }
  
      var description: String {
      get {
          switch self {
          case .Nearest:
              return "Nearest Station"
          case .LastShown:
              return "Last Displayed Station"
          case .List:
              return "Station List"
          case .Specific(let stationNumber):
              return "Station #\(stationNumber)"
          }
      }
      }
  }
  </code></pre>
  
  <p>I'd like to use these values as keys in a dictionary. Declaring a Dictionary yields the expected error that StationSelector doesn't conform to Hashable. Conforming to Hashable is easy with a simple hash function:</p>
  
  <pre><code>var hashValue: Int {
  get {
      return self.toInt()
  }
  }
  </code></pre>
  
  <p>However, <code>Hashable</code> requires conformance to <code>Equatable</code>, and I can't seem to define the equals operator on my enum to satisfy the compiler.</p>
  
  <pre><code>func == (lhs: StationSelector, rhs: StationSelector) -&gt; Bool {
      return lhs.toInt() == rhs.toInt()
  }
  </code></pre>
  
  <p>The compiler complains that this is two declarations on a single line and wants to put a <code>;</code> after <code>func</code>, which doesn't make sense, either.</p>
  
  <p>Any thoughts?</p>