Are the sorting algorithms used by the various sorting methods in NSArray stable? (As in are they "stable sort" algorithms, where items with the same sort key have their relative orders preserved.)
相关问题
- How to toggle on Order in ReactJS
- PHP Recursively File Folder Scan Sorted by Modific
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Sort TreeView Automatically Upon Adding Nodes
- Swift - hide pickerView after value selected
In the doc, no details are given as to the final order of identical items.
Therefore, I feel making any assumptions about the order would be a bad idea. Even if you determine experimentally what the order is, this could change based on the number of items in the array or which version of iOS runs the sort.
For me, I would stick with the promises provided by documentation.
Stable sort is not guaranteed unless you use
NSSortStable
. From the documentation on NSSortOptions:If you need to guarantee a stable sort, try something like:
The only "official" answer I've found about this is a 2002 mailing list post by Chris Kane from Apple:
I don't know whether this is still true, given how old the post is, but it's probably best to assume that
NSArray
's sorting methods are not stable.