The basics of this: get the modified copy, update the modified copy, and then update the request with the mutable copy.
let mutableRequest = ((self.request as NSURLRequest).mutableCopy() as? NSMutableURLRequest)! URLProtocol.setProperty(true, forKey: "", in: mutableRequest) self.request = mutableRequest as URLRequest
Better to use to avoid forced reversal.
guard let mutableRequest = (self.request as NSURLRequest).mutableCopy() as? NSMutableURLRequest else { // Handle the error return } URLProtocol.setProperty(true, forKey: "", in: mutableRequest) self.request = mutableRequest as URLRequest
Note: self.request must be declared var not let .
source share