title: Swift - Switch statement not working
body: <p>I want to store a UIColor in NSUserDefaults. However, this lead to some problems, so I figured I could save the UIColor as String to be converted back into a UIColor.</p>
  
  <p>I decided to do this with a switch statement: </p>
  
  <pre><code>switch bc {
      case "UIColor.redColor()":
          blockColour = UIColor.redColor()
      case "UIColor.orangeColor()":
          blockColour = UIColor.orangeColor()
      case "UIColor.blueColor()":
          blockColour = UIColor.blueColor()
      case "UIColor.greenColor()":
          blockColour = UIColor.greenColor()
      case "UIColor.blackColor()":
          blockColour = UIColor.blackColor()
      case "UIColor.grayColor()":
          blockColour = UIColor.grayColor()
      case "UIColor.purpleColor()":
          blockColour = UIColor.purpleColor()
      default:
          println("ERROR!")
      }
  </code></pre>
  
  <p>However, I get errors on every case line, saying:</p>
  
  <pre><code>Type 'String' does not conform to protocol 'IntervalType'
  </code></pre>
  
  <p>I'm sure this can't be the most effective method or the easiest way to do this, but it's the only way I could figure out how to save a UIColor in NSUserDefaults.</p>
  
  <p>What's the problem?</p>
  
  <p>EDIT: Preceding code that shows how bc is defined:</p>
  
  <pre><code>var bc : String!
  var blockColour : UIColor!
  
  var userDefaults = NSUserDefaults.standardUserDefaults()
  
      if var blockColourString : AnyObject = userDefaults.valueForKey("blockColour") {
          blockColourString = userDefaults.valueForKey("blockColour")
          bc = blockColourString as String
      }
      else {
          var blockColourString : AnyObject = "UIColor.orangeColor()"
          userDefaults.setValue(blockColourString, forKey: "blockColour")
          bc = blockColourString as String
      }
  
      userDefaults.synchronize()
  </code></pre>