Re-establishing KVO in Managed objects after undo
Hi, I have some places in my code where I have managed objects that need to observe various key paths. If one of these objects has been deleted by the user, and then they undo, I need to re-establish the KVO. As undo doesn't call awakeFromFetch, I need to do this somewhere else. I have awakeFromSnapshotEvents: implemented for 10.6+ users, and it works fine, but is only available in 10.6, whereas I need to also have something that will work on 10.5. How did you accomplish this before 10.6? TIA Gideon ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Re-establishing KVO in Managed objects after undo
There's no easy way to do this. But if you are observing other managed objects, you might be able to use +(NSSet*)keyPathsForValuesAffectingKey instead. (Search for registering dependent keys in the docs.) If you are observing something that is not part of your data model, you might try using mechanisms other than KVO to keep your data model updated. KVO can be a world of hurt when used the way you are using it. There are old threads on this topic. See, for example, Strange NSManagedObjectContextObjectsDidChangeNotification behavior. Dave On 2010-05-01, at 9:42 AM, Gideon King wrote: Hi, I have some places in my code where I have managed objects that need to observe various key paths. If one of these objects has been deleted by the user, and then they undo, I need to re-establish the KVO. As undo doesn't call awakeFromFetch, I need to do this somewhere else. I have awakeFromSnapshotEvents: implemented for 10.6+ users, and it works fine, but is only available in 10.6, whereas I need to also have something that will work on 10.5. How did you accomplish this before 10.6? TIA Gideon ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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/dave.fernandes%40utoronto.ca This email sent to dave.fernan...@utoronto.ca ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Re-establishing KVO in Managed objects after undo
On Sat, May 1, 2010 at 9:34 AM, Dave Fernandes dave.fernan...@utoronto.ca wrote: If you are observing something that is not part of your data model, you might try using mechanisms other than KVO to keep your data model updated. KVO can be a world of hurt when used the way you are using it. There are old threads on this topic. See, for example, Strange NSManagedObjectContextObjectsDidChangeNotification behavior. Agreed. Your controller should listen for MOC notifications to find out when to start and stop observing objects. After all, that's what NSArrayController does. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Re-establishing KVO in Managed objects after undo
Thanks guys - will look into that. On 02/05/2010, at 3:11 AM, Kyle Sluder wrote: On Sat, May 1, 2010 at 9:34 AM, Dave Fernandes dave.fernan...@utoronto.ca wrote: If you are observing something that is not part of your data model, you might try using mechanisms other than KVO to keep your data model updated. KVO can be a world of hurt when used the way you are using it. There are old threads on this topic. See, for example, Strange NSManagedObjectContextObjectsDidChangeNotification behavior. Agreed. Your controller should listen for MOC notifications to find out when to start and stop observing objects. After all, that's what NSArrayController does. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Re-establishing KVO in Managed objects after undo
Gideon King (gid...@novamind.com) on 2010-05-01 09:42 said: Hi, I have some places in my code where I have managed objects that need to observe various key paths. Why? (I'm curious... I've never used such a pattern.) Perhaps instead you could override setters so that they perform other actions in addition to just changing the attribute/relationship. Sean ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com
Re: Re-establishing KVO in Managed objects after undo
It's inherited code from someone else, and am trying to work that out myself too...luckily there are only 5-6 of them, so I should be able to sort it out. Just looking at it now, I think a little refactoring should sort it out, and remove the need for KVO. On 02/05/2010, at 5:23 AM, Sean McBride wrote: Gideon King (gid...@novamind.com) on 2010-05-01 09:42 said: Hi, I have some places in my code where I have managed objects that need to observe various key paths. Why? (I'm curious... I've never used such a pattern.) Perhaps instead you could override setters so that they perform other actions in addition to just changing the attribute/relationship. Sean ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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 arch...@mail-archive.com