How to do a natural sort on an NSArray?
Posted
by Cory Imdieke
on Stack Overflow
See other posts from Stack Overflow
or by Cory Imdieke
Published on 2010-05-17T02:12:48Z
Indexed on
2010/05/17
2:20 UTC
Read the original article
Hit count: 347
I've got an array of objects, and I need them sorted by their "title" key. It's currently working, though it's using an ASCII sort instead of a natural sort. The titles are filenames, so they look like this:
file1
file2
file3
...
file10
file11
file12
I'm getting, as you would expect:
file1
file10
file11
file12
file2
file3
...
Does anyone know if there is a way built-in to the NSArray sorting functionality to get this natural sorting as opposed to the alphabetical sort? I found some generic algorithms, but I was hoping for something built-in...
© Stack Overflow or respective owner