There's a hook that catches every delete on the back-end, (beforeDelete
in cloud code), but from the question, it sounds like that's the wrong place to catch, because the file in need of deletion is local.
Parse recently open-sourced the SDK. Perusing the code. It looks like the delete variants ultimately all call deleteInBackground
. So one idea -- a little too clever, IMO -- would be to override only that one. But I think it would be unwise to depend on this undocumented fact.
If you control the caller side, one idea is to just make a policy to never call delete directly, and provide an "otuswebDelete" method to do the object and file delete.
If you don't control the caller (or don't trust yourself to remember your own policy), I think you're better off, under your current design, to just override the few variants:
– delete
– delete:
– deleteInBackground
– deleteInBackgroundWithBlock:
– deleteEventually
They can all just call super
to delete, then call a method in the subclass to delete the local file. Not so bad, IMO.
Finally, for reasons too numerous to detail here, I'm in the habit of "wrapping" my PFObjects (an NSObject
subclass that has a PFObject
property) rather than subclassing them.
The burden of this approach is a little tedium to create the accessors for the properties, but in return I get more control of (a) the use of SDK methods (as in your issue), (b) serialization, (c) fetching an managing related objects, (d) more...