不太了解 NSMetadataQuery
我正在寻找一个可以从 Cocoa API 中使用的类来对整个系统执行 Spotlight 搜索。我查看了 NSMetadataQuery 并相信这是这个类,但是我不明白如何做到这一点;主要是NSPredicate
。例如,我想在系统中搜索名为“test123.html”的文件并获取其完整路径。非常感谢示例。我的代码:
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];
这返回 0 个结果。为什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
kMDItemSFName
应该是kMDItemFSName
kMDItemSFName
should bekMDItemFSName