How to sort file names correctly like Finder in objective-c

I am linking NStableView with NSMutableArray names and other file names. Simple binning and sorting by comparison: incorrectly sorts filenames like finder. Please let me know if I need to define a custom selector to sort file names and how?

+2


a source to share


2 answers


Since Mac OS X 10.6, just use -[NSString localizedStandardCompare:]

.



For earlier systems see Technical Q&A QA1159: Sorting As Finder

+3


a source


using a custom selector on the TableColumn attribute, especially thanks to KennyTM



// category on NSString for custom comparison
@interface NSString (FilesComparison)
- (NSComparisonResult)compareFiles:(NSString*)file;
@end
@implementation NSString (FilesComparison) 
- (NSComparisonResult)compareFiles:(NSString*)file {
    return [(NSString *)self compare:file options: NSCaseInsensitiveSearch|NSNumericSearch];
}
@end

      

+2


a source







All Articles