I am monitoring my iCloud sandbox (iOS) using an NSMetaDataQuery
are recommended - and all is working well.
I'm attempting to use the NSMetadataQueryUpdateChangedItemsKey
in the NSMetadataQueryDidUpdateNotification
in order to efficiently update my internal model of the file system. Challenge I have is that when a file is moved/renamed, how can I know the original file path - so I can update my model?
It appears that the NSMetaDataItem
objects are persistent (i.e. the same object instance is updated when the path changes) so I could use the pointer value as a kind of index into my model. However - I'd be taking advantage of an apparent implementation detail (which could change.) Perhaps NSMetaDataItems
are recycled when memory runs low?
Anyone know how this should be done (or if it is actually the case that NSMetaDataItem
objects persist for the lifetime of the NSMetaDataQuery
- and stay 'attached' to the same file system item.)
Documentation mentions that results are suitable for Cocoa Bindings, which means that most likely those objects are persistent.
I use more hardcore combination of
NSFilePresenter
andNSMetadataQuery
running side by side to monitor documents in container.NSFilePresenter
has convenient API for detecting when files were being moved:func presentedSubitem(at oldURL: URL, didMoveTo newURL: URL)
For that to work though when you move files in container you have to explicitly notify file coordinator that you're moving file (see points 1-3):