Ich habe einige Dateien in nsdocumentdirectory, wenn ich die Datei, die Erträgen die Datei mit zufälligem position.I geholt diesen folgenden Code verwenden:wie Datei aus Nsdocumentverzeichnis nach ihrem Namen sortieren?
NSString *downloadDirectory = [Utility bookDownloadFolder];
NSString *bookFolder = [[_selectedBook.zipFile lastPathComponent] stringByDeletingPathExtension];
NSString *bookFolderFinal = [downloadDirectory stringByAppendingPathComponent:bookFolder];
NSMutableArray *retval = [NSMutableArray array];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSArray *files = [fileManager contentsOfDirectoryAtPath:bookFolderFinal error:&error];
und der Ausgang ist wie folgt aus:
Dateien (“ 1.jpg, 1.txt, 10.jpg, 10.txt 11.jpg, 11.txt, 12.jpg, 12.txt, 13.jpg "," 13.txt "," 2.jpg "," 2.txt "," 3.jpg "," 3.txt "," 4.jpg "," 4.txt "," 5.jpg ", "5.txt", "6.jpg", "6.txt" "7.jpg", "7.txt", "__MACOSX"
Aber ich möchte die Ausgabe in aufsteigender Reihenfolge wie: Dateien ("1.jpg", "1.txt", "2.jpg", "2 .txt ",)
Wenn ich localizedCaseInsensitiveCompare verwende, um das Array zu sortieren, funktioniert es in diesem Fall nicht, wenn ich localizedCaseInsensitiveCompare verwende, dann ist die Ausgabe nur so. (" __MACOSX "," 1.jpg "," 1.txt "," 10.jpg "," 10.txt "," 11.jpg "," 11.txt "," 12.jpg "," 12.txt "," 13.jpg "," 13. txt "," 2.jpg "," 2.txt "," 3.jpg "," 3.txt "," 4.jpg "," 4.txt "," 5.jpg ",)
Mögliche Duplikate von [Wie sortiere ich ein NSArray alphabetisch?] (Http://StackOverflow.com/questions/1351182/How-to-sort-a-nsarray-alphabetisch) – Droppy
Kein localizedCaseInsensitiveCompare funktioniert in diesem Fall nicht, wenn ich localizedCaseInsensitiveCompare verwenden dann ist die Ausgabe wie diese nur. ("__MACOSX", "1.jpg", "1.txt", "10.jpg", "10.txt", „11.jpg “ "11.txt" "12.jpg" "12.txt" "13.jpg" "13.txt" "2.jpg" "2.txt" , "3.jpg", "3.txt", "4.jpg", "4.txt", "5.jpg", ) –
Sie wollen [diese one] (http://stackoverflow.com/questions/11075644/sort-nsmutablearray-with-strings-die-enthaltenden-Nummern) dann. Sie müssen jedoch Ihre Meinung klären; willst du es numerisch oder nicht? – Droppy