title: Swift : Use of unresolved identifier 'json'
body: <p>I'm currently developing my first iOS app using Swift 2.0 and Xcode 7.0.1.</p>
  
  <p>I'm getting a strange little error that I can't seem to fix:</p>
  
  <pre><code>        var err: NSError?
  </code></pre>
  
  <p>The original code:</p>
  
  <pre><code>        //var json = NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers, error: &amp;err) as? NSDictionary
  </code></pre>
  
  <p>Swift2 rewrite code:</p>
  
  <pre><code>        do {
              if let json = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary {
                  print(json)
              }
          } catch {
              print(error)
          }
  </code></pre>
  
  <p>Use of unresolved identifier 'json' before rewriting</p>
  
  <pre><code>        if let parseJSON = json {
              var resultValue = parseJSON["status"] as? String
              print("result: \(resultValue)")
  
              var isUserRegistered:Bool = false;
              if(resultValue=="Success") { isUserRegistered = true; }
  
              var messageToDisplay:String = parseJSON["message"] as! String!;
              if(!isUserRegistered)
              {
                  messageToDisplay = parseJSON["message"] as! String!;
              }
  
              dispatch_async(dispatch_get_main_queue(),{
  
                  //Display alert message with confirmation.
                  var myAlert = UIAlertController(title:"Alert", message:messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert);
  
                  let okAction = UIAlertAction(title:"Ok", style:UIAlertActionStyle.Default){ action in
                      self.dismissViewControllerAnimated(true, completion: nil);
                  }
  
                  myAlert.addAction(okAction);
                  self.presentViewController(myAlert, animated:true, completion:nil);
              });  
          }
  </code></pre>
  
  <p>The error is thrown at this line:</p>
  
  <pre><code>            if let parseJSON = json {
  </code></pre>
  
  <p>Can someone please tell me what I'm doing wrong here?</p>