Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > sorting records in a NSMutableDictionary

sorting records in a NSMutableDictionary
Thread Tools
Forum Regular
Join Date: Jan 2002
Location: Hungary
Status: Offline
Reply With Quote
Feb 4, 2002, 07:52 PM
 
Hey everyone...

I have a tableView which has records that are stored in a NSMutableDictionary. How can I make my app sort these in ascending order depending on whichever array within an object (a table's column) I specify as the sorting criteria.

Please help me... I have already spent more than two weeks with this problem...

thanks, stupidFish23
nothing is when everything is alright
stupidfish23@mac.com ICQ: 153647416
     
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Feb 4, 2002, 08:34 PM
 
Hello ...

No help here, but something of a related issue.

I have an NSMutableArray of NSStrings and I want to sort the entries according to, say, the second word in each string. I have no problem writing a comparator method to call via NSMutableArray's "sortUsingSelector:", but I can't figure out where the comparator should _live_. Do I have to sub-class NSString just to provide a "secondWordComparator:" method (not to mention a method for recasting a given NSString into this new subclass and who-knows-what other bookkeeping methods)?


Regards,

DayLateDon
     
Mac Enthusiast
Join Date: Jul 2001
Status: Offline
Reply With Quote
Feb 4, 2002, 08:38 PM
 
Originally posted by stupidFish23:
<STRONG>I have a tableView which has records that are stored in a NSMutableDictionary. How can I make my app sort these in ascending order depending on whichever array within an object (a table's column) I specify as the sorting criteria.</STRONG>
The authors of the Learning Cocoa book use an NSMutableArray of the keys and keep that sorted. There's no concept in Cocoa of a sorted dictionary (at least that I can see).
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Feb 4, 2002, 09:16 PM
 
Don't use an NSDictionary, it makes things messy. NSArray is definetly the way to go. Make an array of objects that have x different attributes, and then create a method that, given the type of attribute, can order objects soley based on the given attribute. Sounds complicated, but it's really easy, since NSArray has a method built in that does all the sorting given the comparative NSSelector. I forget the name, but it's painfully obvious if you look at the docs.

HTH,
F-bacher
     
Forum Regular
Join Date: Aug 2001
Location: Vienna, Austria
Status: Offline
Reply With Quote
Feb 4, 2002, 10:14 PM
 
Keys in NS*Dictionaries are unsorted. You have to use a NSMutableArray which includes many NSDictionaries (one for each row).
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Feb 4, 2002, 10:59 PM
 
NSDictionary (and its mutable cousin) are inherently unordered. The suggestion of keeping an array of the keys is your best bet.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Forum Regular
Join Date: Jan 2002
Location: Hungary
Status: Offline
Reply With Quote
Feb 5, 2002, 03:50 AM
 
Wow, people, thanks for the tons of replies...

Gonna play around with that one a bit...
nothing is when everything is alright
stupidfish23@mac.com ICQ: 153647416
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:38 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2