• 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: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?


  • Subject: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • From: Erik Stainsby <email@hidden>
  • Date: Wed, 01 Aug 2012 06:00:46 -0700

Hi Mark,

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?

~ Erik



On 2012-08-01, at 3:20 AM, Mark Woollard <email@hidden> wrote:

> Can you give a bit more info on what is stored in your NSArray? NSString? NSManagedObject? NSDictionary? Something else?
> Regards
> Mark
>
> On 1 Aug 2012, at 06:01, Erik Stainsby <email@hidden> wrote:
>
>> The NSSortDescriptor documentation seems especially opaque to me tonight.
>> Surely there is a useful short description somewhere … ?  *whimper*
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> 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:
>>
>> This email sent to email@hidden
>


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
      • From: Jens Alfke <email@hidden>
    • Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
      • From: Keary Suska <email@hidden>
    • Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
      • From: Michael Babin <email@hidden>
  • Prev by Date: Re: NSTask and NSPipe has buffering issues?
  • Next by Date: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Previous by thread: Re: NSTask and NSPipe has buffering issues?
  • Next by thread: Re: Sorting NSArray -- advice on how to accomplish a "simple" alpha ordering?
  • Index(es):
    • Date
    • Thread