> On Feb 11, 2020, at 4:59 AM, Gabriel Zachmann via Cocoa-dev 
> <cocoa-dev@lists.apple.com> wrote:
> 
> First of all, what are the advantages/disadvantages of either method?

Sort descriptors are data; selectors are [references to] code. So a sort 
descriptor lets you configure the sorting without having to write any custom 
code, and there's a standard API for it. For this reason they're used by 
NSTableView to represent the column sorting, and by NSArrayController.

If you're hardcoding the sort order, which it looks like you are, then it's 
probably simpler just to go the code route and sort using a selector. (Note 
that there are also sort methods that take an NSComparator, which is just a 
typedef for a block. This is very convenient for custom sorts.

> Second, I was wondering if I could write the second method like this:
> 
>    imagefiles_ = [imagefiles_ sortedArrayUsingSelector: 
> @selector(localizedStandardCompare:) ];

That won't work since imageFiles_ is a mutable array, and 
-sortedArrayUsingSelector: returns an immutable array. Use the mutable version, 
-sortArrayUsingSelector:, instead.

—Jens
_______________________________________________

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