Michael Diabolo
Michael Diabolo

Reputation: 7

Delete Object from CoreData

I want to Delete an Object from CoreData in an Alert but it´s comes this error. All that i have found was the Function from the TableView to Delete it with Swipe but i want it in an Alert. 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

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")
            }

       }))

Upvotes: 0

Views: 481

Answers (2)

Peter Foti
Peter Foti

Reputation: 5674

deletedObjects is a property on NSManagedObjectContext that returns a 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)

Upvotes: 1

vadian
vadian

Reputation: 285260

It's just a typo: deleteObject(, (without d and without s),
probably happened due to misleading code completion.

Upvotes: 3

Related Questions