Using Spotlight in Cocoa

混江龙づ霸主 提交于 2019-12-12 12:35:24

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/3719010/using-spotlight-in-cocoa

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