awakeFromFetch with non-managed property
I have an NSManagedObject subclass with some image data in an NSData property (image开发者_StackOverflow社区Data
), 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?
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.
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.
精彩评论