macosnsmetadataquery

Do I need NSMetadataQueryDidFinishGathering, if I watch every NSMetadataQueryGatheringProgress?


NSMetadataQuery posts NSMetadataQueryGatheringProgress as the query runs and then NSMetadataQueryDidFinishGathering, when it's done. I'm receiving both notifications, and they work fine.

I notice, though, that when I get NSMetadaQueryDidFinishGathering, there's never any new data since the final gathering progress. Is that guaranteed to always be the case?

I've read the docs for both these constants, and it's not clear to me if that's what was intended.

If I deal with incoming results in NSMetadataQueryDidFinishGathering?, will that always get me every result?


Solution

  • As far as I understand the documentation this is true for a static search, but it is not true for a live search.

    A NSMetadataQueryDidFinishGathering is send after the initial search (gathering process). You can stop then the search inside your did finish method with -stopQuery. Then, of course, no new data will be delivered.

    But you can simply pause the search with -disableUpdate, too. Then you read the results and restart the (live) search with -enableUpdates. Then you will get updates after the finish notification, i. e. when the user changes files to match the search criteria.