title: Swift clarification about optional with NSDictionary and valueForKey
body: <p>I'm trying to learn Swift porting my Obj-C code that manage an HttpRequest, but when I receive the response in JSON I've issue trying to access the NSDictionary.</p>
  
  <p>Example of JSON:</p>
  
  <pre><code>{
      response =     {
          id = 1234;
          name = a2b3n4h5lkl3;
      };
  }
  </code></pre>
  
  <p>I receive from HttpRequest completionHandler</p>
  
  <pre><code>(dictionary:NSDictionary?, error:NSError?) -&gt; Void
  </code></pre>
  
  <p>than I want to get some values from the NSDictionary? and save them to a var:</p>
  
  <pre><code>let responseDictionary = dictionary!.valueForKey("response") as? NSDictionary
  
  println(responseDictionary!)                        // The informations are present correctly
  
  if (responseDictionary!.count &gt; 0) {
  
      var testStringAccessId:NSString? = responseDictionary!.valueForKey("id")! as? NSString
  
      println(testStringAccessId)                     // print nil
  
      println(responseDictionary!.valueForKey("id")!) // print the correct value
  
      if let stringAccessId = responseDictionary!.valueForKey("id")! as? NSString {
          self.accessID = stringAccessId
      } else {
          println("Error No Access ID")               // Enter here
          completion(success: false)
          return                                      // The function exit with error
      }
  }
  </code></pre>
  
  <p>I tried many combination but maybe I'm missing something in the optional use. The strange thing it's that if I comment the return in the error case and try to get another value from the NSDictionary this one is correct, like:</p>
  
  <pre><code>if let stringAccessNAME = responseDictionary!.valueForKey("name")! as? NSString {
      self.accessNAME = stringAccessNAME              // I get the correct value saved in the variable
  } else {
      println("Error No Access NAME")
      completion(success: false)
      return
  }
  </code></pre>
  
  <p>Any help please?</p>
  
  <p>Thanks
  Ale</p>
  
  <p><strong>SOLVED</strong>:</p>
  
  <p>Use NSNumber instead of NSString. Thanks to Jesper</p>