当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Using Spotlight in Cocoa

问题描述:

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?

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.

网友答案:

You can use the NSMetadataQuery class or its underlying CFType MDQuery. O'Reilly has published an example.

分享给朋友:
您可能感兴趣的文章:
随机阅读: