title: read a json file in swift
body: <p>hi guys I have a json file in my swift project and I want to read this file and use its content to draw stuff. I created a controller where I have the following. </p>
  
  <pre><code>import UIKit
  
  class MapViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          let jsonData = getJSON("hls.json")
  
          println(jsonData)
  
          let jsonDataResult = parseJSON(jsonData)
  
          println("\(jsonDataResult)")
      }
  
      func getJSON(urlToRequest: String) -&gt; NSData{
          return NSData(contentsOfURL: NSURL(string: urlToRequest)!)!
      }
  
      func parseJSON(inputData: NSData) -&gt; NSDictionary{
          var error: NSError?
          var boardsDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error: &amp;error) as NSDictionary
  
          return boardsDictionary
      }
  }
  </code></pre>
  
  <p>Unfortunately it says: fatal error: unexpectedly found nil while unwrapping an Optional value at the getJSOn function. I have the file called hls.json in my app directory where all my swift files are so I don't know if its because it can't read it or what.. Hope someone can help me out!</p>