Dar*_*rio 0 sorting cocoa objective-c nsmutablearray
NSFileManager *fileManager= [[NSFileManager alloc]init];
NSDirectoryEnumerator *myEnumerator= [fileManager enumeratorAtPath:[[theFolder URLByDeletingLastPathComponent]path]];
int f,size=0;
NSMutableArray *dirList=[[NSMutableArray alloc]init];
NSString *fpath;
while (fpath=[myEnumerator nextObject])
{
[dirList addObject:fpath];
}
[dirList sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
Run Code Online (Sandbox Code Playgroud)
dirList包含类似"name_0012345.tif"的文件名.尽管排序数组不包含文件的顺序,我将在finder中按名称排序.
-sortedArrayUsingSelector:实际上是一个NSArray返回一个新排序数组的方法(你会立即忽略它).您的意思是使用-sortUsingSelector:,这是一种NSMutableArray重新排列现有数组本身的方法.
这是很常见的可可具有用于返回一个对象的经修改版本不可改变的一种方法,以及用于修改所述可变对象本身(另一种方法-stringByAppendingString:和-appendString:,例如).
| 归档时间: |
|
| 查看次数: |
73 次 |
| 最近记录: |