I'm also working on this for the simple reason that it just appears that not 
having sorted dicts (in a straightforward way) is an offense to all that it 
holy and good.  Matt Galloway and others have already published methods for 
doing this, but sometimes, the learning is in the doing.

What I'm currently doing to populate a TVC from a dict is to reference the dict 
in the datastore first.  Ideally, I'd have accessors in the datastore to return 
the sections[sectionNum] and rows[rowNum].

Once I have that dict ref, this is what I'm doing:

   NSDictionary *customerFilters = [DataStore findFiltersForCustomers: 
customers];

   sectionArray = [[NSMutableArray alloc] init];
   rowArray = [[NSMutableArray alloc] init];
   for (id key in customerFilters) {
       id myRowData = [customerFilters objectForKey:key];
       [sectionArray addObject: key];
       [rowArray addObject: myRowData];
       NSLog(@"%@", key);
       NSLog(@"%@", myRowData);
   }

   NSLog(@"%@",sectionArray );
   NSLog(@"%@",rowArray );

IMHO, it's still a PITA and it would seem to make a boatload of sense to be 
able to grab keys and objects/values from dicts simply by using their index, 
without having to code up too much of a solution.





On Aug 1, 2012, at 10:38 AM, Michael Babin wrote:

> On Aug 1, 2012, at 8:00 AM, Erik Stainsby <erik.stain...@roaringsky.ca> wrote:
> 
>> So I have a dictionary like so:  
>> 
>>      NSDictionary * countries = [NSDictionary dictionaryWithObjects:[NSArray 
>> arrayWithObjects:@"Australia",@"Canada",@"United Kingdom",@"United 
>> States",nil] forKeys:[NSArray arrayWithObjects:@"au",@"ca",@"uk",@"us",nil]];
>> 
>> I want to present them alphabetically as menuItems in an NSPopUpButton.  I 
>> grab the list of keys:
>> 
>>      NSMutableArray * sortkeys  = [NSMutableArray arrayWithArray:[countries 
>> allKeys]];
>> 
>> What I have come up with is this:
>> 
>>      [sortkeys sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
>>              return [(NSString*)obj1 compare:(NSString*)obj2 ];
>>      } ];
>> 
>> Is this a sane approach ? Seems a bit fussy to have to spec the cast like 
>> this. Or is this just the what-is of this kind of functionality?
> 
> If your comparison is only going to be a single method call with a single 
> parameter like this, then probably a bit simpler to use:
> 
>       [sortkeys sortUsingSelector:@selector(compare:)];
> 
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to