当我尝试从项目中删除核心数据条目时,遇到错误

cannot invoke 'deleteObject' with an argument list of '([AnyObject]?)'


我认为这基本上是在要求我投射对象,但是当我尝试此操作时,会遇到相同的错误。我的代码如下:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context = appDelegate.managedObjectContext
var error:NSError? = nil
let request = NSFetchRequest(entityName: projectEntityName)
let pred = NSPredicate(format: "projectName = %@", projectName)
                request.predicate = pred
let objects = context?.executeFetchRequest(request, error: &error)
if let objectList = objects {
   for thisProject in objectList {
      thisProject.deleteObject(objects)
   }
}
appDelegate.saveContext()


有人能帮忙吗?

最佳答案

您混合了变量。 deleteObject是NSManagedObjectContext的方法,您将要删除的对象作为参数传递:

if let objectList = objects {
   for thisProject in objectList {
      context!.deleteObject(thisProject)
   }
}

10-08 06:25