删除核心数据条目无法使用参数列表“([AnyObject]?)”调用 'deleteObject'
Delete core data entry cannot invoke 'deleteObject' with an argument list of '([AnyObject]?)'
当我尝试从我的项目中删除核心数据条目时,我遇到了错误
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()
有人可以帮忙吗?
使用as
.
thisProject.deleteObject(objects as! [type])
您混淆了变量。 deleteObject
是NSManagedObjectContext的一个方法,你传入要删除的对象作为参数:
if let objectList = objects {
for thisProject in objectList {
context!.deleteObject(thisProject)
}
}
当我尝试从我的项目中删除核心数据条目时,我遇到了错误
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()
有人可以帮忙吗?
使用as
.
thisProject.deleteObject(objects as! [type])
您混淆了变量。 deleteObject
是NSManagedObjectContext的一个方法,你传入要删除的对象作为参数:
if let objectList = objects {
for thisProject in objectList {
context!.deleteObject(thisProject)
}
}