My iOS UIWebView page is based on Cordova open source framework, and I want to add some customize http headers in its webview URL request, my solution is to add them in the foll
a pure Swift 4 compliance answer should be something like the following:
if let anURL = URL(string: aString) {
var aRequest = URLRequest(url: anURL, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: 5.0)
if let tmpToken = Network.shared.getAuthenticationToken() {
aRequest.setValue(tmpToken, forHTTPHeaderField: "Authorization")
}
self.loadRequest(aRequest)
}
where cachePolicy, timeoutInterval are to be set following your needs, as well as the if let statement in order to get an hypothetical token to be inserted in the request.
The relevant part here is the way you set additional parameters on the URLRequest. No needs to use a Mutable statement anymore. var is the you go on the URLRequest.