Re: Custom Accessors in Core Data
Re: Custom Accessors in Core Data
- Subject: Re: Custom Accessors in Core Data
- From: Quincey Morris <email@hidden>
- Date: Wed, 2 Feb 2011 12:51:56 -0800
On Feb 2, 2011, at 12:37, Gordon Apple wrote:
> I wrote the accessors for both lineSpacing and lineSpaceingNum and it at
> least got through the compiler. I won't know if it really works until I get
> the rest of the scaler/Number accessors done and try it.
I don't believe there's any real difficulty about writing the accessors as such. The danger is in tripping over KVO, and (IIRC) it can be hard to get 2 such properties to behave in lockstep as you would want them to do from a KVO point of view.
If you make *only* a getter for the "...Num" version, then I think it's easy -- you just make it a dependent key via 'keyPathsForValuesAffecting...'.
If you try to make a setter too, then it gets harder to make sure you don't generate too many KVO notifications -- or, worst of all, an infinite number, recursively. As best I recall, avoiding the recursion is not apparently that hard ... until you start to watch what undo/redo does. As usual with Core Data, undo tends to throw a wrench into the best laid plans.
Perhaps I'm misremembering -- perhaps it all falls out neatly in the relatively straightforward case you've described -- but I do have memories of being in KVO hell for days or weeks trying to get this sort of thing working. That's why I suggested you might just avoid the problem completely. :)
_______________________________________________
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