Not quite understanding NSMetadataQuery

你说的曾经没有我的故事 提交于 2019-12-25 08:08:21

问题


I am looking for a class to use from the Cocoa API to perform a Spotlight search on the entire system. I looked at NSMetadataQuery and believe this is the class for this, however I don't understanding how to do this; primarily NSPredicate. I would like to search the system for a file named "test123.html" for example and get its full path. Examples are greatly appreciated. My code:

NSMetadataQuery *q = [[NSMetadataQuery alloc] init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"kMDItemSFName == %@", @"test123456.png"];  
[q setPredicate:predicate];

[q startQuery];
while ([q isGathering]) {
    NSLog(@"%lu", [q resultCount]);
}

[q stopQuery];

This returns 0 results. Why?


回答1:


kMDItemSFName should be kMDItemFSName



来源:https://stackoverflow.com/questions/6397541/not-quite-understanding-nsmetadataquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!