 |
 |
sorting records in a NSMutableDictionary
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2002
Location: Hungary
Status:
Offline
|
|
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 
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
Wow, people, thanks for the tons of replies...
Gonna play around with that one a bit...

|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|