Re: NSManagedObject subclass accessor pattern mystery?
site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com -Dave _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/site_archiver%40lists.apple... On Sep 29, 2008, at 11:44 PM, Michael B Johnson wrote: So I have a CoreData app (10.5.5, 64 bit only) that has a NSManagedObject that has an NSColor* that is part of its data model. Because this color is actually a computed value that we want to cache, it is declared as a property: Have you read the "Non-Standard Persistent Attributes" of the Core Data guide? It gives you several ways of doing this and even uses NSColor as an example: <http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles/...
The easiest way, if you can require 10.5, is to use a transformable attribute. Core Data will automatically transform your NSColor to and from NSData using an NSValueTransformer. In other words, I read my document off of disk, and CoreData magically makes sure that my "color" property is set. But since it never seems to call my setColor: setter, I don't see it happen, which is when I would like to go ahead and cache my separate red, green, and blue properties. Since these are calculated from the color (which is saved), there's no reason to ever store them to disk. If you want to cache the RGB values, you'll probably want to follow the instructions in "Custom Code". Perhaps a pre-calculated getter and an immediate-update setter? In awakeFromFetch and setColor: you could update the RGB values as well as the primitive color. This email sent to site_archiver@lists.apple.com
participants (1)
-
Dave Dribin