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.
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) -> NSData{
return NSData(contentsOfURL: NSURL(string: urlToRequest)!)!
}
func parseJSON(inputData: NSData) -> NSDictionary{
var error: NSError?
var boardsDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
return boardsDictionary
}
}
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!