Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block passed as a parameter to MDQuerySetSortComparatorBlock (Spotlight API) is not getting called

I tried to use MDQuerySetSortComparatorBlock method inside the MDQuery framework to sort the query result list. However, the block passed as a parameter to the method doesn't get called at all. Below is a piece of code that I'm using to make a query request. Any help is appreciated.

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);
like image 323
Shashank Avatar asked Nov 28 '25 22:11

Shashank


1 Answers

The fourth parameter in the mdquerycreate method has been provided for sorting purpose. We can pass an array of attributes to it to sort the results. If the fourth parameter is not NULL, the sortcomparator block gets called.

like image 113
Shashank Avatar answered Nov 30 '25 15:11

Shashank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!