Created
October 20, 2016 17:59
-
-
Save markohlebar/eea6bb9894bcb797198d34c1854ca43b to your computer and use it in GitHub Desktop.
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
func perform(query: String) { | |
NotificationCenter.default.addObserver(self, | |
selector: #selector(didUpdate(with:)), | |
name: Notification.Name.NSMetadataQueryDidUpdate, | |
object: nil) | |
NotificationCenter.default.addObserver(self, | |
selector: #selector(didFinish(with:)), | |
name: Notification.Name.NSMetadataQueryDidFinishGathering, | |
object: nil) | |
metadataQuery = NSMetadataQuery() | |
metadataQuery.predicate = NSPredicate(format: "kMDItemTextContent like[c] %@", query) | |
//NSHomeDirectory() on sandboxed apps is the sandbox itself | |
//http://stackoverflow.com/questions/9553390/how-do-i-get-the-users-home-directory-in-objective-c-in-a-sandboxed-app | |
metadataQuery.searchScopes = ["/Users/mhlebar"] | |
metadataQuery.start() | |
} | |
func didUpdate(with notification: NSNotification) { | |
} | |
func didFinish(with notification: NSNotification) { | |
for item in metadataQuery.results as! [NSMetadataItem] { | |
print(item.value(forAttribute:NSMetadataItemPathKey)!) | |
} | |
metadataQuery.stop() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment