【发布时间】:2021-03-01 13:59:49
【问题描述】:
我正在尝试使用这样的 Appkit 在 本地 macOS 文件夹(不在 iCloud 中)上执行 NSMetadataQuery:
let query = NSMetadataQuery()
query.valueListAttributes = [ NSMetadataItemURLKey ]
//Set the App's Documents folder as the SearchScope
query.searchScopes = [FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!]
NotificationCenter.default.addObserver(self, selector: #selector(handleQueryNotification), name: NSNotification.Name.NSMetadataQueryDidFinishGathering, object: query)
query.enableUpdates()
query.start()
但是,我从未收到查询已完成收集结果的通知。当我将 searchScope 更改为 [NSMetadataQueryUbiquitousDocumentsScope] 时,我确实收到了通知。
从Apple's documentation看来这应该是可能的:
这个数组可以包含代表文件系统目录或查询搜索范围的 NSURL 或 NSString 对象
是不是我做错了什么?
【问题讨论】: