NSMetadataQuery Not Returning Results for Files in macOS 13.6 - Unexpected Empty Results
I'm getting frustrated with I'm trying to configure I tried several approaches but none seem to work... I'm trying to use `NSMetadataQuery` to find specific files in a custom directory on macOS 13.6, but the query is returning empty results even though I can see the files in Finder. I'm initializing the `NSMetadataQuery` and setting up the predicates correctly, but it seems like the queries are either not executing or not finding anything. Hereβs the code Iβm using to set up the query: ```swift import Cocoa class FileSearcher { private var query: NSMetadataQuery! init() { self.query = NSMetadataQuery() self.query.searchScopes = [NSMetadataQueryUserHomeScope] self.query.predicate = NSPredicate(format: "%K == %@", NSMetadataItemFSNameKey, "myFile.txt") NotificationCenter.default.addObserver(self, selector: #selector(queryDidFinishGathering(_:)), name: .NSMetadataQueryDidFinishGathering, object: self.query) self.query.start() } @objc func queryDidFinishGathering(_ notification: Notification) { let results = self.query.results as! [NSMetadataItem] print("Results: \(results)") // Expecting results, but getting an empty array. } } ``` Iβve verified that `myFile.txt` exists in the user's home directory, and I've set the correct search scope. However, the results array is empty when the gathering finishes. I've tried different predicates and scopes, but nothing seems to work. I also checked file permissions, and my application has the appropriate access. What could be causing this scenario? Is there something specific I need to do to ensure that `NSMetadataQuery` is able to find files? Are there any debugging steps or additional configurations that I might be overlooking? For context: I'm using Swift on macOS. Any help would be greatly appreciated! This is part of a larger CLI tool I'm building. Could someone point me to the right documentation? What's the best practice here?