title: Swift enum function with string parameter calling with a parameter of the enum class
body: <p>I'm trying to convert from a string to an enum key value, but I couldn't find any simple method so I hardcoded it, but it still won't work. </p>
  
  <p>I tried using an enum function to return an enum key value from a string, but I can't call it with the string even though I declared it with a String as a parameter. </p>
  
  <p>I then tried to move it to a different class, but the same thing happened.</p>
  
  <p>My relevant code is below.</p>
  
  <pre><code>enum pickedColor: String {
  case green = "71D25E"
  case red = "FF0000"
  case maroon = "800000"
  case yellow = "FFFF00"
  case olive = "808000"
  case lime = "00FF00"
  case aqua = "00FFFF"
  case teal = "008080"
  case blue = "0000FF"
  case navy = "000080"
  case fuchsia = "FF00FF"
  case purple = "800080"
  
  func toEnum(_ colorName: String) -&gt; pickedColor {
      if colorName.elementsEqual("green") {
          return .green
      } else if colorName.elementsEqual("red") {
          return .red
      } else if colorName.elementsEqual("maroon") {
          return .maroon
      } else if colorName.elementsEqual("yellow") {
          return .yellow
      } else if colorName.elementsEqual("olive") {
          return .olive
      } else if colorName.elementsEqual("lime") {
          return .lime
      } else if colorName.elementsEqual("aqua") {
          return .aqua
      } else if colorName.elementsEqual("teal") {
          return .teal
      } else if colorName.elementsEqual("blue") {
          return .blue
      } else if colorName.elementsEqual("navy") {
          return .navy
      } else if colorName.elementsEqual("fuchsia") {
          return .fuchsia
      }  else {
          return .purple
      }
  }
  
  {
  </code></pre>
  
  <p>The code that shows up when I try to call it is this.<a href="https://i.stack.imgur.com/ZJ3PF.png" rel="nofollow noreferrer">Picture1</a></p>
  
  <p>When manually completed, it still shows an error of cannot convert string to pickedColor.</p>
  
  <p>I then moved the code to a new class, however, it still does not work.</p>
  
  <pre><code>class Color {
  
  func toEnum(_ colorName: String) -&gt; pickedColor {
      if colorName.elementsEqual("green") {
          return .green
      } else if colorName.elementsEqual("red") {
          return .red
      } else if colorName.elementsEqual("maroon") {
          return .maroon
      } else if colorName.elementsEqual("yellow") {
          return .yellow
      } else if colorName.elementsEqual("olive") {
          return .olive
      } else if colorName.elementsEqual("lime") {
          return .lime
      } else if colorName.elementsEqual("aqua") {
          return .aqua
      } else if colorName.elementsEqual("teal") {
          return .teal
      } else if colorName.elementsEqual("blue") {
          return .blue
      } else if colorName.elementsEqual("navy") {
          return .navy
      } else if colorName.elementsEqual("fuchsia") {
          return .fuchsia
      } else {
          return .purple
      }
  }
  }
  </code></pre>
  
  <p>The second picture of the wrong parameter is here. <a href="https://i.stack.imgur.com/slDke.png" rel="nofollow noreferrer">Picture2</a></p>
  
  <p>What is going on?</p>