Waiting for NSMetadataQuery to finish?

  • Hi,

    is it somehow possible to wait for an NSMetadataQuery to first give
    back some results, and only then continue in the code?

    Here is my situation: in an NSTextView I want to run a Spotlight
    query on autocomplete and fill the autocomplete drop-down box with
    the results of the query.

    Here is what I do:

    - Within NSTextView's
    completionsForPartialWordRange:indexOfSelectedItem: I construct an
    NSPredicate with the current partial word, along the lines of
    (kMDItemDisplayName like[cd] '*word*') (actually, the query is a bit
    more restricted).
    - I register a handler method (queryHandler:) for
    NSMetadataQueryDidFinishGatheringNotifications.
    - I run the query with the predicate.
    - queryHandler: iterates over the query results and constructs an
    array of autcomplete suggestions from it.
    - Now, what is a clever way to make
    completionsForPartialWordRange:indexOfSelectedItem: return that array?

    I suppose I could somehow halt
    completionsForPartialWordRange:indexOfSelectedItem: until [query
    hasStopped] or ![query isGathering], but that doesn't seem to work
    just like that. Do I have to work with threads here? Should I take a
    completely different approach? Any suggestion is welcome!

    Cheers,
    Knud
    -------------------------------------------------
    Knud Möller, MA
    +353 - 91 - 495086
    Digital Enterprise Research Institute
      National University of Ireland, Galway
    Institiúid Taighde na Fiontraíochta Digití
      Ollscoil na hÉireann, Gaillimh
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today