Re: NSManagedObject subclass accessor pattern mystery?
Re: NSManagedObject subclass accessor pattern mystery?
- Subject: Re: NSManagedObject subclass accessor pattern mystery?
- From: Dave Dribin <email@hidden>
- Date: Tue, 30 Sep 2008 00:23:55 -0500
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/cdNSAttributes.html
>
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.
-Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden