本文介绍了不太了解NSMetadataQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个类来使用Cocoa API在整个系统上执行Spotlight搜索。我看着 NSMetadataQuery ,并相信这是类的,但我不明白如何做到这一点;主要是 NSPredicate 。我想搜索系统中的一个文件名为test123.html例如,并得到其完整路径。非常感谢。我的代码:

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];

这将返回0个结果。为什么?

This returns 0 results. Why?

推荐答案

kMDItemSFName 应为 kMDItemFSName

这篇关于不太了解NSMetadataQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 06:20