Re: While on the subject of: NSOutlineView
Re: While on the subject of: NSOutlineView
- Subject: Re: While on the subject of: NSOutlineView
- From: Sailor Quasar <email@hidden>
- Date: Wed, 30 Jul 2003 18:25:17 -0400
- Resent-date: Wed, 30 Jul 2003 18:29:11 -0400
- Resent-from: Sailor Quasar <email@hidden>
- Resent-message-id: <email@hidden t>
- Resent-to: email@hidden
On Wednesday, July 30, 2003, at 04:11 PM, Chris Hanson wrote:
Well, that's a bit of a problem. There is no inherent order of
objects inside a dictionary. But for a table view data source, you
will need to know which objects to display for which row. So either
you use the row numbers as keys for the dictionary (not all that
efficient) or you need to maintain the order of objects somewhere
else; in an NSArray for instance.
There's always [[myDictionary allKeys] objectAtIndex:row].
If you want to get fancy, you can create an intermediate sorted array
of keys and then use that. Just be sure to use it everywhere instead
of using -[NSDictionary allKeys] directly.
My personal solution to solve this problem was to add yet another
method to my file full of categories on various NS classes.
Specifically, on NSDictionary - (id)nthValue:(unsigned)n. I implemented
it with a loop over [self objectEnumerator], and I had also considered
the [[self allValues] objectAtIndex:] approach. I'm not certain which
one is faster, but it would seem to me somehow that NSEnumerator is,
since the dictionary would already have to iterate all its values to
generate the autoreleased allValues array.
For the record, to date I have added 44 category methods to 11
Foundation/AppKit classes. I like to think I only put methods in this
file if they could be used in more than one application; for category
methods that are application-specific I use application-specific
categories. Of those, I believe I have only one. I certainly don't
argue that everyone could use these utility methods, or that any of
them should be added to the actual Cocoa frameworks; I know what comes
of that debate. However, I also like my code that reads if
([someNSDictionary containsKey:someKey]) better than if
([someNSDictionary objectForKey:aKey] != nil) :).
-- Sailor Quasar, guardian of Leraz's memory
"A face of stone may hide a soul with the deepest Love of all"
Email: email@hidden
-- Sailor Quasar, High Codemaster of the Web, scourge of systems
MacOS is to Windows as Terminus is to Trantor.
Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.