tags:

views:

69

answers:

2

I have some object with name , just like button 1 , button 2 , button 11 ,button 111 , I want to add this object to a array by this order: button 1 ,button 2 , button 11 , button 111, but I found that these object can add the array by thhis order: button 1 , button 11,button 111 , button 2.why ? Thank you for your answer!

A: 

The same way that if you had files of this name in Finder they would order the same way.

To get proper ordering you need to name them button 001, button 002, button 011, etc.

Alternatively, you'll have to write your own sort descriptors.

See here for NSMutableArray sortUsingSelector: and here for NSSortDescriptor

Abizern
Actually, Finder has always used proper numeric sorting in Mac OS X. It's one of the CF and Cocoa sort options. Only in Mac OS did it sort ASCIIbetically.
Peter Hosey
+1  A: 

Use the NSNumericSearch option in your sort comparison.

Peter Hosey
Ignore me, go with what Peter says.
Abizern