Re: NSArrayController + KVO + Core Data Question
Re: NSArrayController + KVO + Core Data Question
- Subject: Re: NSArrayController + KVO + Core Data Question
- From: Ajay Sabhaney <email@hidden>
- Date: Mon, 23 Aug 2010 01:32:37 -0600
> I'm guessing, but you seem to have a managed object with a to-many relationship, and you want to be notified whenever anything is added to or removed from that relationship property. So, observe that property of the managed object, and you're done.
>
> If there's something more complicated going on in the data model, your solution may be more complex, but throwing NSArrayController at the problem is highly unlikely to help with the solution.
Quincey, thank you for the follow up. I do not think I explained my situation clearly so I will try and explain this more clearly.
I have a very simple data model. There is only one entity: Item. Each time I add or remove an Item to the array controller source, I would like my UI view to take action based on the newly added/removed Item. More specifically: I have a very custom view, and each Item entity in the data model corresponds to a Core Animation layer in the view. So if a particular Item entity is removed from the array controller, I'd like to remove a corresponding CALayer from the layer-hosting view. And if a particular Item entity is added to the array controller, I'd like to add a corresponding CALayer to the layer-hosting view.
Currently, my view is observing the arrangedObjects property of NSArrayController. However, all KVO notifications that the view receives are NSKeyValueChangeSetting type changes (as opposed to NSKeyValueChangeInsertion type changes). I would like them to be NSKeyValueChangeInsertion changes so that I may easily add a CALayer corresponding to the newly added Item model.
So to overcome this, I binded the contentArray property of the NSArrayController to a mutable array of mine. So each time I add an Item to the mutable array, the NSArrayController notifies my view, which takes the appropriate action.
[ I am doing something somewhat similar to what you see on the LAST post in this thread to ensure I receive NSKeyValueChangeInsertion type changes:
http://stackoverflow.com/questions/1313709 ]
In case you're wondering why I'm using an NSArrayController and not just an array, it is because NSArrayController currently ties in nicely with file loading and saving, as well as undo and redo. I'm also using some of the selection functionality that NSArrayController provides.
Thinking about this a little more carefully, I'm not sure that using an NSArrayController actually is the best solution in this situation, especially as the data model and the view become more complex....
Comments and suggestions in relation to this as well as my original post are appreciated_______________________________________________
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