Trouble Implementing NSMetadataQuery for Searching Files in macOS 13.6 App - Returns Incomplete Results
I'm converting an old project and I've been working on this all day and I'm trying to implement a file search feature in my macOS app using `NSMetadataQuery` on macOS 13.6. However, I’m encountering an issue where the query returns incomplete results, particularly when searching for files in specific directories. For instance, when I'm querying for `.txt` files in the user's Documents folder, the results are missing several files that I know exist. Here’s the code I’m using: ```swift import Cocoa class FileSearcher: NSObject, NSMetadataQueryDelegate { var query: NSMetadataQuery! override init() { super.init() setupQuery() } func setupQuery() { query = NSMetadataQuery() query.searchScopes = [NSMetadataQueryUserHomeScope] query.predicate = NSPredicate(format: "%K == 'txt'", NSMetadataItemFSNameKey) query.delegate = self query.start() } func metadataQuery(_ query: NSMetadataQuery, didFinishGathering results: NSMetadataQuery) { for i in 0..<results.resultCount { let item = results.result(at: i) as! NSMetadataItem print(item.value(forAttribute: NSMetadataItemPathKey) ?? "") } } } ``` I’ve also tried setting the `searchScopes` to `NSMetadataQueryUserDocumentScope`, but it doesn’t seem to help. Additionally, I verified that the files are there and accessible by the app. I’m running this code on an M1 MacBook Pro, and I’m wondering if there’s anything specific to macOS 13.6 that I might be missing. Are there any best practices or additional configurations needed to ensure all relevant files are returned? Any help would be appreciated! Is there a better approach? I'm using Swift 3.9 in this project. Am I missing something obvious?