title: NSURLConnection Using iOS Swift
body: <p>I am trying to follow <a href="http://jamesonquave.com/blog/developing-ios-apps-using-swift-tutorial-part-2/">this tutorial</a> and connect to a JSON api using Swift and <code>NSURLConnection</code>. I can see that it is hitting the url but the <code>connectionDidFinishLoading</code> does not seem to fire. </p>
  
  <pre><code>import UIKit
  
  class Remote: NSObject {
  
      var host = "http://localhost:3000"
      var query = String()
      var data: NSMutableData = NSMutableData()
  
      func connect(query:NSString) {
          self.query = query
          var url = self.document()
          var conn = NSURLConnection(request: url, delegate: self, startImmediately: true)
      }
  
      func endpoint() -&gt; NSURL {
          var query = self.host + self.query
          return NSURL(string: query)
      }
  
      func document() -&gt; NSURLRequest {
          return NSURLRequest( URL: self.endpoint() )
      }
  
      func connection(didReceiveResponse: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
          // Recieved a new request, clear out the data object
          self.data = NSMutableData()
      }
  
      func connection(connection: NSURLConnection!, didReceiveData conData: NSData!) {
          // Append the recieved chunk of data to our data object
          self.data.appendData(conData)
      }
  
      func connectionDidFinishLoading(connection: NSURLConnection!) {
          // Request complete, self.data should now hold the resulting info
          // Convert the retrieved data in to an object through JSON deserialization
          var err: NSError
          var jsonResult: NSDictionary = NSJSONSerialization.JSONObjectWithData(self.data, options:    NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
  
          println(jsonResult.count)
      }
  
  
  }
  
  
  // Excecute the code
  
  var remote = Remote()
  remote.connect("/apis")
  </code></pre>
  
  <p>At this point I am just trying to see the data that is returned. I would like to hook it into a view controller once I am sure this is working. Is there something wrong with doing it this way and that is causing an issue?</p>