Created
February 10, 2019 00:53
-
-
Save dagronf/3d03094a7ee79c1f91607f4c365fba91 to your computer and use it in GitHub Desktop.
How to use Spotlight searches in Swift (basic example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let query = MDQueryCreate(kCFAllocatorDefault, "kMDItemContentType = com.apple.application-bundle" as CFString, nil, nil) | |
MDQueryExecute(query, CFOptionFlags(kMDQuerySynchronous.rawValue)) | |
let count = MDQueryGetResultCount(query); | |
for i in 0 ..< count { | |
let rawPtr = MDQueryGetResultAtIndex(query, i) | |
let item = Unmanaged<MDItem>.fromOpaque(rawPtr!).takeUnretainedValue() | |
if let path = MDItemCopyAttribute(item, kMDItemPath) as? String { | |
print(path) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// let query = MDQueryCreate(kCFAllocatorDefault, "kMDItemFSLabel = 6" as CFString, nil, nil)
// let query = MDQueryCreate(kCFAllocatorDefault, "kMDItemContentType = com.apple.application-bundle" as CFString, nil, nil)
// let query = MDQueryCreate(kCFAllocatorDefault, "kMDItemUserTags == 'cat' && kMDItemUserTags == 'dog'" as CFString, nil, nil)