While dealing with UIWebView specific application we need to clean UIWebView content without loading empty html page to achieve our goal. Here i have written in detail single line solution for this problem.
This solution will optimise app performance as you can remove unused content from UIWebView. Its always critical for mobile app development to maintain memory stack as low as possible and unload unused components for better optimisations.
Specifically while dealing with UIWebView we may need some way for it to clean UIWebView content but don’t want to load empty page as its again same to load page. It will be achieved using single line of code given as below for Objective C as well as Swift.
Objective C code
NSString *urlString = @”https://www.google.com/”; NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; [_webView loadRequest:urlRequest];
Swift code
let url = URL(string: “about:blank”) let requestObj = URLRequest(url: url! as URL) webView.loadRequest(requestObj)
Its looks small but very useful way to clean UIWebView content in many cases and as per user’s requirements. Here you can find code with implementation.