I’m working on an app where there are two different NSManagedObject types that might point to a user-taken video via an NSURL. My thought was to create another NSManagedObject (video) to hold the URL reference, and when no other objects point to the video object, call the file system to remove the file pointed to by the NSURL.
Relative cocoa newbie question: what is the appropriate cocoa idiom for this? Coming from C++, I’d subclass video to override the delete function (which Apple’s documentation seems to suggest is not ideal). I could imagine writing a category of video which has some extra functionality but this would need to be explicitly called?
Thanks for any ideas.
You can override the
prepareForDeletionmethod in your customNSManagedObjectsubclass to delete the underlying file when the object is about to be deleted. It’s designed for exactly this purpose.