Re: Core Data design question: receiving KVO notifications of partially mutated objects
Re: Core Data design question: receiving KVO notifications of partially mutated objects
- Subject: Re: Core Data design question: receiving KVO notifications of partially mutated objects
- From: Ben Trumbull <email@hidden>
- Date: Mon, 2 Nov 2009 15:35:50 -0800
>> If your issue is that drawing or recalculation is occurring too
>> frequently after KVO changes, you can consider coalescing and deferring
>> the observers' actions instead of performing them synchronously. This
>> can be valuable even for less complex KVO issues.
>>
>> You could also refactor the 3 properties into 1 object.
>
> Alas, that would require 1) persistent store migration (painful on 10.5)
> and 2) I find it very handy to be able to bind 'colour' to a colourwell
> and 'width' and 'height' to text fields. Perhaps I have bent my model
> too much in favour of my UI also. :) But anyway, this 'Rectangle'
> object was just an example. My real app is a bit harder to explain.
>
>> Or use an
>> NSNotification instead of KVO to adjust the granularity of notifications
>> to better suit your drawing code.
>>
>> This doesn't really have anything to do with Core Data. However, for
>> NSManagedObject, Core Data already provides the change coalescing and
>> NSNotifications for you. You can respond within
>> NSManagedObjectContextObjectsDidChangeNotification instead.
>
> Perhaps NSManagedObjectContextObjectsDidChangeNotification is the thing
> I have overlooked! I currently use it almost nowhere but have tonnes
> and tonnes of KVO observing going on.
>
> I'll have to RTFM on NSManagedObjectC
> ontextObjectsDidChangeNotification. Questions that pop to mind though:
> is it safe for me to fetch? to create/delete/mutate ManagedObjects?
I'd recommend performing a selector after delay 0. You can inspect the objects and decide what you want to do with them. The notification is posted from within the change tracking code, so making changes could possibly result in them getting caught in between 1 user event and the next.
- Ben
_______________________________________________
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