这是" fetchData"的代码。方法。我想将此代码实现到try - Catch
块中。
如何更改。
var error: NSError?
if let fetchedResults = managedObjectContext.executeFetchRequest(fetchRequest, error: nil) as? [NSManagedObject]
{
//if not nil
players = fetchedResults
}
else {
println("could not fetch data \(error), \(error?.userInfo)")
}
答案 0 :(得分:3)
这是你可以做到的方式......
do {
fetchedResults = try managedObjectContext.executeFetchRequest(fetchRequest)
//Success....Do your stuff
} catch let error as NSError {
//Failure ...catch error
print("could not fetch data \(error), \(error?.userInfo)")
}