更新时间:2022-11-13 23:30:38
看起来正确的方法是设置排序描述符您创建它时的查询。这些内容:
Looks like the right way to do this would be to set the sort descriptor of your query when you create it. Something along these lines:
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
[query setSearchScopes:[NSArray arrayWithObject:
NSMetadataQueryUbiquitousDocumentsScope]];
NSPredicate *pred = [NSPredicate predicateWithFormat: @"%K ENDSWITH '.bin'",
NSMetadataItemFSNameKey];
[query setPredicate:pred];
NSSortDescriptor *sortDescriptor =
[[[NSSortDescriptor alloc] initWithKey:NSMetadataItemFSContentChangeDateKey
ascending:FALSE] autorelease]; //means recent first
NSArray *sortDescriptors = [NSArray arrayWithObjects:
sortDescriptor,
nil];
[query setSortDescriptors:sortDescriptors];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(queryDidFinishGathering:)
name:NSMetadataQueryDidFinishGatheringNotification
object:query];
[query startQuery];