Josh Kahane
Josh Kahane

Reputation: 17169

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'?

Upvotes: 1

Views: 86

Answers (2)

wattson12
wattson12

Reputation: 11174

Assuming you are using swipe to delete on the table view it may be better to is use tableView:canEditRowAtIndexPath: and only allow editing if isSpecial is false. This would stop the user hitting the delete button and nothing happening

Upvotes: 2

paulbailey
paulbailey

Reputation: 5346

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.

Upvotes: 1

Related Questions