• 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
Sorting an array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sorting an array


  • Subject: Sorting an array
  • From: Gabriel Zachmann via Cocoa-dev <email@hidden>
  • Date: Tue, 11 Feb 2020 13:59:44 +0100

I have some trivial questions regarding sorting a simple array of strings.

I used to use this code:

    NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey: nil
ascending: YES];//TODO: raus
    [imagefiles_ sortUsingDescriptors: @[sd] ];

where imagefiles_ is an NSMutableArray* .

Now, in the developer doc
(
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Collections/Articles/Arrays.html#//apple_ref/doc/uid/20000132-SW5)

I saw a different method. Following that, I was thinking of sorting my array
like this:

    NSArray * sorted_images = [imagefiles_ sortedArrayUsingSelector:
@selector(localizedStandardCompare:) ];
    imagefiles_ = [NSMutableArray arrayWithArray: sorted_images];

First of all, what are the advantages/disadvantages of either method?

Second, I was wondering if I could write the second method like this:

    imagefiles_ = [imagefiles_ sortedArrayUsingSelector:
@selector(localizedStandardCompare:) ];


Thanks a lot in advance.



_______________________________________________

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 an array
      • From: Jens Alfke via Cocoa-dev <email@hidden>
    • Re: Sorting an array
      • From: Sandor Szatmari via Cocoa-dev <email@hidden>
  • Prev by Date: Xcode can't launch System Preferences any more
  • Next by Date: MFI Device Picker not displaying
  • Previous by thread: Xcode can't launch System Preferences any more
  • Next by thread: Re: Sorting an array
  • Index(es):
    • Date
    • Thread