NSArrayController for unordered collection (a Set)
NSArrayController for unordered collection (a Set)
- Subject: NSArrayController for unordered collection (a Set)
- From: Bob Peterson <email@hidden>
- Date: Tue, 4 Jan 2005 07:42:20 -0500
I'm still stuck trying to come up with a way to design a mutable
property that is a mathematical set, not an ordered array. Key-Value
Coding and Binding seems geared to ordered model arrays. The available
methods all assume there is an index to insert at or get from. I can
ignore the index in my implementation of the
-insertObject:in<KEY>AtIndex: method. But there's no sensible way to
fake -objectIn<Key>AtIndex:. I can artificially define an ordering and
maintain a indexing array (or dispense with the set altogether), but
this seems a silly thing to force on my models simply to suit
NSControllers.
Perhaps I should create a SetController which knows how to use NSSet
properly. I expect I'd have to ignore the standard collection (i.e.
NSArray-oriented) Key-Value Coding model-side API. Would that be the
right path?
I understand ordering has to be achieved for UI presentation, but I
expect that is the province of arrangeObjects, not my model.
Or am I not making sense?
\bob
P. S. The Combatants example shows clearly how to map KVC onto an
array-like collection of scalars for read-only access. It works
because it does not try to mutate the collection, and the model
presents the scalars in the same order every time.
Originally, I wrote:
I have a fixed-order collection of items for the user to see and edit.
The user cannot change the order of items, but NSArrayController
seems to be designed for just this.
MMalcolm's page has an example of a filtered array controller, but it
doesn't override methods like insertObject:atArrangedObjectIndex:. Is
it proper to subclass NSArrayController and tell it to ignore the
index value for inserts and just add the new object into its natural
position?
Related to this is the content array. My model is more naturally an
NSSet of uniquely keyed objects, whose display order is irrelevant to
the model. All these messages that specify indexes bother me. I'd
rather be passing objects or object keys around. But unless someone
has an NSSetController I don't know about, I expect I'll have to
subclass NSArrayController and use an array instead of a set.
Am I reading these documentation pages right, or do I need to set
aside the eggnog and RTFM harder?
On Dec 26, 2004, at 6:31 PM, mmalcolm crawford wrote:
On Dec 26, 2004, at 3:11 PM, Bob Peterson wrote:
MMalcolm's page has an example of a filtered array controller, but it
doesn't override methods like insertObject:atArrangedObjectIndex:.
Is it proper to subclass NSArrayController and tell it to ignore the
index value for inserts and just add the new object into its natural
position?
See the Combatants example, which uses a fixed set of instance
variables.
You can simply override the indexed accessors in the container object.
mmalc
_______________________________________________
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