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 protected])

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/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to