• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Subclassing dictionaries?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing dictionaries?


  • Subject: Re: Subclassing dictionaries?
  • From: Chris Hanson <email@hidden>
  • Date: Thu, 4 Sep 2003 08:46:26 -0500

On Thursday, September 4, 2003, at 07:47 AM, John Timmer wrote:
The way I'm seeing it, the ideal tableView data source has a mutable array
of dictionaries. Look up the rowIndex, pass in the column ID as a key, get
out your object. Dead easy, but makes sorting them a hassle.

[snip]

Maybe I'm missing some other good design idea that would accomplish the same
thing. If so, I'd love to hear it.

This is exactly the sort of issue my BDControl framework was intended to solve. It's an Open Source (BSD-licensed) framework that includes both qualifier and sort ordering objects; the latter are what you want.

BDControl <http://bdistributed.com/Projects/BDControl/>

You can easily keep a sorted array in your table data source using BDSortOrdering <http://bdistributed.com/Projects/BDControl/Documentation/Classes/ BDSortOrdering.html>:

BDSortOrdering *lastNameOrdering
= [BDSortOrdering sortOrderingWithKey:@"lastName"
selector:BDCompareCaseInsensitiveAscending];
BDSortOrdering *firstNameOrdering
= [BDSortOrdering sortOrderingWithKey:@"firstName"
selector:BDCompareCaseInsensitiveAscending];

NSArray *orderings = [NSArray arrayWithObjects:lastNameOrdering,
firstNameOrdering, nil];

cachedData = [[self arrayInDataSource]
sortedArrayUsingKeyOrderArray:orderings];

The above sorts your data array first by its contained objects' lastName property, and then by its contained objects' firstName property using key-value coding. The objects in your data array don't have to be dictionaries; they can be instances of any classes that support key-value coding. In your case, you'd probably only use one ordering, not multiple.

When your user clicks a table column or modifies your data array, then, all you have to do is re-run this to get the sorted version to feed to the NSTableView.

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal 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.

References: 
 >Re: Subclassing dictionaries? (From: John Timmer <email@hidden>)

  • Prev by Date: Split Buttons: How do I make em?
  • Next by Date: Subclassing NSNotificationCenter
  • Previous by thread: Re: Subclassing dictionaries?
  • Next by thread: RE: Subclassing dictionaries?
  • Index(es):
    • Date
    • Thread