I am trying to follow this tutorial in order to save the Local Cache of UIWebView in my app.
I had to convert a few lines to swift 2 but i cannot find the way to solve the issue when add to NSManagedObjectContext save an argument of type NSError.
from the picture you can understand better what I mean.
How could I fix this? The code I'm using is:
func saveCachedResponse () {
print("Saving cached response")
// 1
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context = delegate.managedObjectContext!
// 2
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")
// 3
var error: NSError?
let success = context.save(&error)
if !success {
print("Could not cache the response")
}
}