我刚下载了新的Xcode 7.0测试版,并从Swift 1.2迁移到Swift 2.迁移显然没有改变整个代码,实际上是一个方法saveContext(),直到抛出2行错误:
if moc.hasChanges && !moc.save() {
Run Code Online (Sandbox Code Playgroud)
二元运算符'&&'不能应用于两个Bool操作数
和
调用可以抛出,但它没有标记为'try',并且没有处理错误
该方法如下所示:
// MARK: - Core Data Saving support
func saveContext () {
if let moc = self.managedObjectContext {
var error: NSError? = nil
if moc.hasChanges && !moc.save() {
// 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. …Run Code Online (Sandbox Code Playgroud)