如何刷新JSON缓存?

时间:2016-03-01 17:16:04

标签: json xcode swift

我正在使用Haneke来缓存远程JSON。缓存效果很好但是当我更改远程JSON文件并调用fetch(多次)时仍然从缓存中获取旧数据。有什么方法可以强制获取更新缓存吗?

谢谢!

我添加

我项目中的Hanekeswift文件

然后 进口Haneke

    _ = NSTimer.scheduledTimerWithTimeInterval(0.0001, target: self, selector: Selector("sayHello"), userInfo: nil, repeats: false)

    func sayHello()
{
    data = dataJsonFromURL("http://www.arabfono.com/show22.php")
    myTable.reloadData()

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("NCell", forIndexPath: indexPath) as! TableViewCell22

    cell.backgroundColor = UIColor .clearColor()

    let mindata = (data[indexPath.row] as! NSDictionary)

    cell.selectionStyle = UITableViewCellSelectionStyle.None

    cell.titleNews!.text = mindata["title_topic"] as? String
    cell.timeNews!.text = mindata["created_date"] as? String
    cell.LabelNews!.text = mindata["view_topic"] as? String




    if let urlImg = NSURL(string: (mindata["img_topic"] as? String)!)
    {
        cell.imgNews.hnk_setImageFromURL(urlImg, placeholder: nil, format: nil, failure: nil, success: nil)
    }
func dataJsonFromURL(url:String)->NSArray
{
    if let data = NSData(contentsOfURL: NSURL(string: url)!) {
        return ((try! NSJSONSerialization.JSONObjectWithData(data, options: [])) as! NSArray)
    }
    else{
        return data
    }

}

0 个答案:

没有答案