2014-07-24 30 views

回答

2

你有一个指针传递给一个可选的NSError对象。 作为一个例子,这是从Xcode的模板代码,如果你创建一个iOS应用程序,并选择 “使用核心数据”复选框:

func saveContext() { 
    if let moc = self.managedObjectContext { 
     var error: NSError? = nil 
     if moc.hasChanges && !moc.save(&error) { 
      // Replace this implementation with code to handle the error appropriately. 
      // ... 
      NSLog("Unresolved error \(error), \(error!.userInfo)") 
      abort() 
     } 
    } 
} 
5
func saveContext() { 
    if managedObjectContext.hasChanges { 
     do { 
      try managedObjectContext.save() 
     } catch let nserror as NSError { 
      // Replace this implementation with code to handle the error appropriately. 
      // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
      print("Unresolved error \(nserror), \(nserror.userInfo)") 
      abort() 
     } 
    } 
} 
相关问题