无法在Alamofire中禁用缓存(Xcode 9 - swift 4)
问题描述:
我使用cannon答案here在调用almofire时禁用缓存,但我仍然获取每个请求的旧数据,并且tableView未更新! 这里是我的代码:无法在Alamofire中禁用缓存(Xcode 9 - swift 4)
let myurl = URL(string: "HERE_MY_URL")!
var myURLRequest = URLRequest(url: myurl)
myURLRequest.cachePolicy = .reloadIgnoringLocalCacheData
Alamofire.request(myURLRequest).response { response in
}
问题在哪里?
答
我在viewWillAppear中FUNC加入这个代码,也许它并不完美的答案,但它的工作原理
URLCache.shared.removeAllCachedResponses()
对于初学者你贴的用途'NSMutableURLRequest'代替'URLRequest' – Malik
@Malik的链接了答案,如果我使用NSMutableURLRequest,我得到这个错误与请求:参数类型'NSMutableURLRequest'不符合预期的类型'URLRequestConvertible' – aqeel