I am trying to follow this tutorial to save the local UIWebView cache in my application.
I had to convert several lines to swift 2, but I can’t find a way to solve the problem if I add an argument of type NSError to NSManagedObjectContext.
from an image that you can understand better what I mean.

How can i fix this? The code I'm using is:
func saveCachedResponse () {
print("Saving cached response")
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context = delegate.managedObjectContext!
let cachedResponse = NSEntityDescription.insertNewObjectForEntityForName("CachedURLResponse", inManagedObjectContext: context) as NSManagedObject
cachedResponse.setValue(self.mutableData, forKey: "data")
cachedResponse.setValue(self.request.URL!.absoluteString, forKey: "url")
cachedResponse.setValue(NSDate(), forKey: "timestamp")
cachedResponse.setValue(self.response.MIMEType, forKey: "mimeType")
cachedResponse.setValue(self.response.textEncodingName, forKey: "encoding")
var error: NSError?
let success = context.save(&error)
if !success {
print("Could not cache the response")
}
}
source
share