NSManagedObject 和类别/子类
我正在开发一个应用程序,其中有两种不同的 NSManagedObject 类型,它们可能通过 NSURL 指向用户拍摄的视频。我的想法是创建另一个 NSManagedObject(视频)来保存 URL 引用,当没有其他对象指向视频对象时,调用文件系统删除 NSURL 指向的文件。
相关可可新手问题:合适的可可习语是什么?来自 C++,我将 video 子类化以覆盖删除函数(Apple 的文档似乎表明这并不理想)。我可以想象编写一个具有一些额外功能的视频类别,但这需要显式调用?
感谢您的任何想法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以重写自定义
NSManagedObject
子类中的prepareForDeletion
方法,以便在即将删除对象时删除底层文件。它就是为了这个目的而设计的。You can override the
prepareForDeletion
method in your customNSManagedObject
subclass to delete the underlying file when the object is about to be deleted. It's designed for exactly this purpose.