1

I know I can enable caching with NSURLRequest

  if reachability.isReachable {
             urlRequestCache=NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: 10)
        }
        else {
            urlRequestCache = NSURLRequest(URL: url!, cachePolicy: NSURLRequestCachePolicy.ReturnCacheDataElseLoad, timeoutInterval: 60)
        }
       theWebView.loadRequest(urlRequestCache)

But I couldn't find any way directly on WkWebView to achieve this.

Durai Amuthan.H
  • 31,670
  • 10
  • 160
  • 241
  • Possible duplicate of [Cache for WKWebView](http://stackoverflow.com/questions/30864893/cache-for-wkwebview) – Vizllx Jan 28 '16 at 08:42
  • @Vizllx - That question is about NSURLRequest or NSURLSession accompanied with WkWebView.But My question is how to achieve by just using the WkWebView – Durai Amuthan.H Jan 28 '16 at 09:00

1 Answers1

2

Swift 4:

var webView = WKWebView()
if let url = URL(string: string) {
        var request = URLRequest(url: url)
        request.cachePolicy = .returnCacheDataElseLoad
        webView.load(request)
}
Async-
  • 3,140
  • 4
  • 27
  • 49