Re: How to tell an object to notify its KVOs that one of its properties needs to be re-cached...
Re: How to tell an object to notify its KVOs that one of its properties needs to be re-cached...
- Subject: Re: How to tell an object to notify its KVOs that one of its properties needs to be re-cached...
- From: Quincey Morris <email@hidden>
- Date: Sat, 25 Jul 2009 15:41:08 -0700
On Jul 25, 2009, at 14:04, Steven Degutis wrote:
When we have an object who has a property that's generated based on
other
properties, usually we implement the
+keyPathsForValuesAffecting[PropertyName] class method.
What I'm trying to do is basically the same thing for a property on my
NSManagedObject, but traversing a relationship.
My model is simple; I have two Entities, App and Version (I'm
creating an
appcast-generating app). There is a dynamic property - (NSString*)
appcast;
which is generated based on all the details of the app and its
versions
relationships. When the App's properties are changed, the -appcast
string is
re-cached, and all bindings are updated appropriately, simply
because I
implemented +keyPathsForValuesAffectingAppcast, as per the statement
above.
However, when any properties on any of a specific App's Versions (to-
many
relationship) change, the -appcast property is not generated
appropriately.
Is there a way to have this dynamic property re-cached any time
certain
(any) properties on its "versions" relationship are changed?
So far, I've tried to include "key paths" such as
"versions.versionNumber"
in the NSSet returned from the aforementioned method, but that just
throws
an exception that the key "versionNumber" does not exist on NSSet.
Yes, you can't run a key path through a collection property like that.
Even if you could, it wouldn't be desirable, because it would mean
that the number of objects being (automatically) observed could grow
exponentially, in general, though in your case I'd imagine there's
only a small number of version objects per app.
I can think of three ways of proceeding (in increasing order of pain):
1. Observe the managed object context's
NSManagedObjectContextObjectsDidChangeNotification, and invoke [app
will/didChangeValueForKey: @"appcast"] pairs for each app affected by
a change.
2. Force the "versions" property to change when a Version object
changes. That is, override the Version property setters to do (say)
self.app = self.app as well as the appropriate setPrimitiveValue: ... .
3. Have each app manually observe each property of each version in
"versions", and observe "versions" itself so you can add/remove the
other observations as required.
Or maybe I'm overlooking something obvious that's easier.
_______________________________________________
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