简体   繁体   English

从CoreData删除对象

[英]Delete Object from CoreData

I want to Delete an Object from CoreData in an Alert but it´s comes this error. 我想从Alert中的CoreData中删除一个对象,但这是此错误。 All that i have found was the Function from the TableView to Delete it with Swipe but i want it in an Alert. 我所发现的只是从TableView中通过滑动将其删除的功能,但我希望在警报中使用它。 Thanks for Help. 感谢帮助。

Cannot call value of non-function type `Set<NSManagedObjekt>`

Whats does this error mean ? 这个错误是什么意思? I make that as!NSManagedObject in the code 我将其作为代码中的NSManagedObject

Here wos the Code from the Alert to delete an Object: 这里从警报中删除了删除对象的代码:

DeleteAlert.addAction(UIAlertAction(title: "Delete", style: .Destructive, handler: { (action) -> Void in

            let indexPath = self.BookTableView.indexPathForSelectedRow


            mgdContext.deletedObjects(book[indexPath!.row] as! NSManagedObject)

            do {
                try self.mgdContext.save()
            } catch {
                print("error")
            }

       }))

It's just a typo: deleteObject( , (without d and without s ), 这只是一个错字: deleteObject( ,(没有d和没有s ),
probably happened due to misleading code completion. 可能是由于误导代码完成而发生的。

deletedObjects is a property on NSManagedObjectContext that returns a Set<NSManagedObject> . deletedObjectsNSManagedObjectContext上的一个属性,该属性返回Set<NSManagedObject> Im not really sure how your code compiles passing in an argument, but suffice it to say you should be using func deleteObject(_ object: NSManagedObject) 我不太确定您的代码如何编译传入参数,但足以说明您应该使用func deleteObject(_ object: NSManagedObject)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM