CoreData, NSArrayController
CoreData, NSArrayController
- Subject: CoreData, NSArrayController
- From: Arved von Brasch <email@hidden>
- Date: Thu, 4 May 2006 17:59:26 +1000
Greetings,
I have a CoreData application and have a few questions with problems
I haven't been able to solve on my own.
1. I have a mixed static / dynamic NSPopUpButton. The menu should
get its dynamic items from the NSArrayController filled in by the
user in a NSTableView. In order to populate the NSPopUpButton, I'm
trying to be notified whenever the user modifies the NSTableView.
I've read all I could find about Keyed Value Observing, and figured
that I could register my controller to the NSArrayController bound
(Is 'bound' the correct nomenclature for past tense bindings?) to the
table. The trouble is I haven't been able to find a key that
actually does this. The best I've been able to do in my controller's
awakeFromNib is:
[myArrayController addObserver: self forKeyPath: @"arrangedObjects"
options: NSKeyValueObservingOptionNew context: NULL];
This only seems to get me 2 notifications when the application starts
up. Any other ideas? Is there a list of key values that actually
says when a particular observed key will send notifications? Is this
even the best approach for this?
2. My second problem with this set up deals with the insertion and
editing of rows in an NSTableView. When a new item is added to an
NSArrayController through the add: binding and displayed in an
NSTableView, the NSSortDescriptors seem to be ignored. This also
seems to be the case when an entry is edited. Is there a way to get
the sorting happening automatically through bindings, or do I have to
write my own "glue" code for the add button, or write a subclass of
NSArrayController?
3. Finally, a question of style. I have two CoreData entities that
are in a relationship. The main entity can have multiple names, but
only one of them is considered "main". I want the main name to
appear in a NSTableView. I tried using a NSFetchedProperty, but I
couldn't get this to work at all. In the end, I bound the
relationship name to the table column and used a value transformer to
pull the main name out, like so:
- (id)transformedValue: (id)item {
return [[[[item allObjects] filteredArrayUsingPredicate:
[NSPredicate predicateWithFormat: @"main == 1"]] objectAtIndex: 0]
valueForKey: @"name"];
}
(I can guarantee that only one name will have the main flag set.)
The main problem with this, of course, is that the sorting on the
table column will not work. This was easily fixed by writing a
category on NSSet so that it now supports compare: for this
particular situation. My question is about the style of this
solution. It seems simple enough to me, but also feels a little
kludgy. Is there a better way to accomplish this?
I appreciate any help that anyone can offer.
Cheers,
Arved von Brasch
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden