Alamofire版本3中,我将NSURLRequest.CachePolicy.returnCacheDataDontLoad用于请求缓存

let URLRequest = NSMutableURLRequest(url: URL(string: url)!)
    URLRequest.cachePolicy = NSURLRequest.CachePolicy.returnCacheDataDontLoad
    Alamofire.request(URLRequest){...}

但是我怎样才能在Alamofire 4和swift 3中使用cachePolicy呢?
谢谢

最佳答案

我到处找,结果发现:

    let TheURL = DEFAULT_APP_URL + "api/getList?Id="+ID
    let urlString = NSURL(string: TheURL)
    var mutableURLRequest = URLRequest(url: urlString! as URL)
    mutableURLRequest.httpMethod = "GET"
    mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
    mutableURLRequest.cachePolicy = NSURLRequest.CachePolicy.returnCacheDataElseLoad


    Alamofire.request(mutableURLRequest)
        .responseJSON
       {....}

关于ios - iOS Swift Alamofire缓存政策,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39976416/

10-13 04:56