Yeah i saw this but i was not understand or find how to use it. i use this function and get an enumerator for materialized items but how am i supposed to use this enumerator to get list of materialized items?
Can you give me an example or describe how to do it?
My colleague hasn't responded the above comment, and so I'm joining this discussion.
The materialized items enumerator can be used with materializedItemsDidChange(completionHandler:) to track the materialized item set in the following way:
-
The system calls materializedItemsDidChange(completionHandler:)
when the materialized item set changes.
-
You grab the materialized items enumerator, and then call enumerateItems(for:startingAt:) to trigger an enumeration.
-
The system delivers the updated items to the observer NSFileProviderEnumerationObserver by calling didEnumerate(_:).
Assuming that you use the extension as the observer, the code is like the following:
| extension Extension: NSFileProviderEnumerationObserver { |
| public func didEnumerate(_ updatedItems: [any NSFileProviderItemProtocol]) { |
| for item in updatedItems { |
| print("item.isDownloaded = \(String(describing: item.isDownloaded))") |
| } |
| } |
| |
| public func finishEnumerating(upTo nextPage: NSFileProviderPage?) { |
| print("\(#function)") |
| } |
| |
| public func finishEnumeratingWithError(_ error: any Error) { |
| print("\(#function): \(error)") |
| } |
| |
| |
| |
| public func materializedItemsDidChange(completionHandler: @escaping () -> Void) { |
| print("\(#function)") |
| |
| let fileProviderManager = NSFileProviderManager(for: domain) |
| if let enumerator = fileProviderManager?.enumeratorForMaterializedItems() { |
| enumerator.enumerateItems(for: self, startingAt: NSData() as NSFileProviderPage) |
| } |
| completionHandler() |
| } |
| } |
Best,
——
Ziqiao Chen
Worldwide Developer Relations.