在Cocoa中使用Spotlight [英] Using Spotlight in Cocoa
问题描述
我可以使用Cocoa中的Spotlight API(它们存在,对吗?)来确定Spotlight(在右上角)是否匹配给定的filePath和给定的字符串?
Can I use the Spotlight APIs (they exist, right?) in Cocoa to determine if Spotlight (in the upper-right corner) would match a given filePath with a given string?
换句话说,给定一个filePath(如/Users/enchilada/Desktop/MapOfUSA.pdf)和一个字符串(如Virginia),我如何知道Spotlight会在Virginia将在右上角Spotlight搜索中键入? (你可以想象,在所示的例子中,它可能匹配,因为美国的PDF地图可能包含Virgina。)
In other words, given a filePath such as "/Users/enchilada/Desktop/MapOfUSA.pdf", and a string such as "Virginia", how would I tell if Spotlight would show this file when "Virginia" would have been typed in the upper-right Spotlight search? (As you can imagine, in the example shown, it would probably be matched, because a PDF map of the USA probably contains Virgina.)
如果可能,一个简单的代码
If possible, a simple code piece to do this would be appreciated.
推荐答案
您可以使用 NSMetadataQuery
类或其基础CFType MDQuery
。 O'Reilly发布了一个示例。
这篇关于在Cocoa中使用Spotlight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!