Ios JSON未在swift中更新
我正在开发一个swift应用程序,它使用来自url的JSON。但是在JSON中进行更改时,它不会在应用程序中更新。这是我正在使用的代码Ios JSON未在swift中更新,ios,json,swift,Ios,Json,Swift,我正在开发一个swift应用程序,它使用来自url的JSON。但是在JSON中进行更改时,它不会在应用程序中更新。这是我正在使用的代码 let urlAsString = "http://domain/json.json" let url = NSURL(string: urlAsString)! let urlSession = NSURLSession.sharedSession() let jsonQuery = urlSession.dataTaskWithUR
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()
我认为苹果正在缓存旧值共享会话可能会缓存数据并阻止刷新。您需要创建自己的NSURLSession并设置请求缓存策略。请参阅此答案以获取代码
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary