Search code examples
iphoneobjective-cipaduitableviewcore-data

Stop Specific CoreData Record Being Deleted?


I have CoreData setup in my app and I have an entity with an attribute 'isSpecial' boolean. For the records where 'isSpecial' is true, I want those records to not be deletable by the user from the UITableView it is displayed within.

So how can I do this? How do I directly see that the cell selected by the user 'isSpecial'?


Solution

  • You can subclass NSManagedObject for your entity (if you haven't already), and override validateForDelete: to check the isSpecial property of the object.

    You should also call super's implementation, as detailed here.

    If and when you want to delete it programmatically, you'll just need to set isSpecial to NO before you attempt the delete.