awakeFromFetch 具有非托管属性

发布于 2024-10-27 00:58:00 字数 390 浏览 4 评论 0原文

我有一个 NSManagedObject 子类,其中 NSData 属性 (imageData) 中包含一些图像数据,该子类会自动保留。从网络加载数据后,我还使用从数据创建的图像设置了自定义 NSImage 属性 (image)。

问题是,如果对象出现故障,当我访问 image 属性时,不会调用 awakeFromFetch,因为它不是由 Core 处理的数据。我当然可以覆盖 image 访问器并确保加载属性(通过访问 imageData),但如果有一种方法可以让 awakeFromFetch 就更好了 正常调用。有什么建议吗?

I have an NSManagedObject subclass with some image data in an NSData property (imageData), which is automatically persisted. After loading the data from the network I also set a custom NSImage property (image) with an image created from the data.

The problem is that if the object is a fault, awakeFromFetch is not called when I access the image property, since it is not handled by Core Data. I can of course override the image accessor and make sure the properties are loaded (by accessing imageData) but it would be nice if there was a way to have awakeFromFetch invoked as normal. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗藏城府 2024-11-03 00:58:00

根据 TechZen 的建议,我现在执行提取请求,并将 returnsObjectsAsFaults 设置为 NO。每次获取对象时从缓存中提取所有数据当然并不理想,但就我而言,我总是立即使用数据,因此这是可以接受的。

As per TechZen's suggestion, I now execute the fetch request with returnsObjectsAsFaults set to NO. It's of course not ideal to pull all data from the cache each time the object is fetched, but in my case I always use the data immediately so it's acceptable.

你怎么敢 2024-11-03 00:58:00

您似乎想做两件矛盾的事情,您希望主要实体保持故障但能够访问其属性。你不能那样做。根据定义,故障没有属性/属性,因为它只是对象图中的占位符。如果您希望主对象保持故障状态,则应该将 UIImage 移动到其自己的实体并将其链接到主对象。然后,您应该能够遍历对象图来获取 UIImage,而不会触发主对象的错误占位符的加载。

You seem to want to do two contradictory things, you want the main entity to remain fault but be able to access its attributes. You cannot do that. A fault by definition has not attributes/properties because it is just a placeholder in the object graph. If you want your main object to remain a fault, you should move the UIImage to its own entity and link it to the main object. You should then be able to walk the object graph to obtain the UIImage without triggering the loading of the main object's fault placeholder.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文