I'm working on an swift app which is using JSON from an url. But when making changes in the JSON it doesn't update in the application. This is the code I'm using
let urlAsString = "http://domain/json.json"
let url = NSURL(string: urlAsString)!
let urlSession = NSURLSession.sharedSession()
let jsonQuery = urlSession.dataTaskWithURL(url, completionHandler: { data, response, error -> Void in
if (error != nil) {
println(error.localizedDescription)
}
var err: NSError?
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
if (err != nil) {
println("JSON Error \(err!.localizedDescription)")
}
var i = 1
while i <= jsonResult.count / 2 {
let title = i.description + "t"
self.feeds.insert(jsonResult[i.description] as NSString, atIndex: 0)
self.feedst.insert(jsonResult[title] as NSString, atIndex: 0)
i++
}
dispatch_async(dispatch_get_main_queue(), {
self.tableView.reloadData()
})
})
jsonQuery.resume()
I tried to make som de-bugging and come up with that the problem might be in this part:
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
I think Apple is caching the old values