coredata: custom accessors
coredata: custom accessors
- Subject: coredata: custom accessors
- From: Roland King <email@hidden>
- Date: Sun, 7 Feb 2010 11:18:25 +0800
I have two questions about coredata custom accessors, I've been reading the section about them, here's the code suggested for the setter of a property of type NSRect, in this instance the NSRect is cached in a local instance variable in the class.
- (void)setBounds:(NSRect)aRect
{
[self willChangeValueForKey:@"bounds"];
bounds = aRect;
[self didChangeValueForKey:@"bounds"];
NSString *rectAsString = NSStringFromRect(aRect);
[self setValue:rectAsString forKey:@"boundsAsString"];
}
Assuming I don't cache the object in an instance variable in the class, because in my case I don't really need to, I can calculate it on the fly and do not expect that to be a performance issue, should the willChangeValueForKey: and didChangeValueForKey: calls bracket the entire method so the setters of the underlying attributes (the persistent ones) are complete before the call to didChangeValueForKey:? My concern here is that the didChangeValueForKey: method could trigger something to go read the transient property, but if I've not set the underlying persistent properties yet, it won't work. Or should you not nest like that and I should set the persistent variables first, then call willChange.. and didChange... afterwards with nothing between them?
Other question is, why do we have to use the setValue:<value> forKey: instead of just invoking [ self setBoundsAsString: ]. _______________________________________________
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