Enes Karaosman Enes Karaosman - 8 months ago 87
Swift Question

How to clear cache on UIWebView in swift?

I'm using tableview to display different pdfs locally. For example;

pdf1 -> "1.pdf"
pdf2 -> "2.pdf"
pdf3 -> "3.pdf"

In my first click, there is no problem but when I tap again it loads different pdf. Ex: I tap pdf2 but it loads pdf1.

Can you help me in this issue, I'm new to swift..


You can easily do it with ;

NSURLCache.sharedURLCache().diskCapacity = 0
NSURLCache.sharedURLCache().memoryCapacity = 0

Also use like this;

let url = NSURL(string: "http://www.web.com")
let url_request = NSURLRequest(URL: url,
    cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData,
    timeoutInterval: 5.0)

let webView = UIWebView()