Reputation: 129
Playing with core data and got stuck with this in Swift 2.0
var error: NSError?
let fetchedResults =
managedContext.executeFetchRequest(fetchRequest,
error: &error) as? [NSManagedObject]
Xcode error says "Extra argument in call" and when I remove error:&error
it says "error not handled", so what's the new syntax?
Upvotes: 1
Views: 630
Reputation: 93141
In Swift 2.0 you have to use exception handling:
var fetchedResults : [NSManagedObject]?
do {
fetchedResults = try managedContext.executeFetchRequest(fetchRequest) as? [NSManagedObject]
} catch let error as NSError {
print("Error \(error.localizedDescription)")
}
Upvotes: 2