我尝试在 MDQuery 框架内使用 MDQuerySetSortComparatorBlock 方法对查询结果列表进行排序。但是,作为参数传递给该方法的块根本不会被调用。下面是我用来发出查询请求的一段代码。任何帮助表示赞赏。
queryString = [NSString stringWithFormat:@"kMDItemDisplayName == \'*a*\'cd"];
CFStringRef query = (__bridge CFStringRef)(queryString);
queryReference = MDQueryCreate(NULL, query, (__bridge CFArrayRef)([NSArray arrayWithObjects:(id)kMDItemDisplayName, nil]), NULL);
MDQuerySetSortComparatorBlock(queryReference, ^CFComparisonResult(const CFTypeRef *attrs1, const CFTypeRef *attrs2) {
NSLog(@"Block called");
return kCFCompareLessThan;
});
MDQuerySetSearchScope(queryReference, (__bridge CFArrayRef)([NSArray arrayWithObjects:(id)kMDQueryScopeComputer, nil]), 0);
MDQueryExecute(queryReference, kMDQueryWantsUpdates);