如何在iOS中使用Swift在特定时间缓存从web服务获取的数据?

如何在iOS中使用Swift在特定时间缓存从web服务获取的数据?,ios,swift,caching,Ios,Swift,Caching,我从web服务中获得了很多图像。我想缓存它。我想知道是否有任何方法可以缓存特定时间的数据,例如1天。您应该使用 要清除缓存,您可以查看以下部分:您可以使用翠鸟库执行此操作。谢谢@Moritz let downloader = ImageDownloader() let urlRequest = URLRequest(url: URL(string: "https://httpbin.org/image/jpeg")!) downloader.download(urlRequest) { res

我从web服务中获得了很多图像。我想缓存它。我想知道是否有任何方法可以缓存特定时间的数据,例如1天。

您应该使用


要清除缓存,您可以查看以下部分:

您可以使用翠鸟库执行此操作。谢谢@Moritz
let downloader = ImageDownloader()
let urlRequest = URLRequest(url: URL(string: "https://httpbin.org/image/jpeg")!)

downloader.download(urlRequest) { response in
    print(response.request)
    print(response.response)
    debugPrint(response.result)

    if let image = response.result.value {
        print(image)
    }
}