[SOLVED] Waiting for NSMetadataQuery to finish?
[SOLVED] Waiting for NSMetadataQuery to finish?
- Subject: [SOLVED] Waiting for NSMetadataQuery to finish?
- From: Knud Hinnerk Möller <email@hidden>
- Date: Thu, 19 Oct 2006 13:48:19 +0100
Hi,
yesterday I had this problem:
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.
I think I have a solution (it seems to work), using CFRunLoops.
Basically, after starting the query in the NSTextView's delegates
textView:completions:forPartialWordRange:indexOfSelectedItem:, I
begin a new run loop. At the end of the call-back funtion listening
to NSMetadataQueryDidFinishGatheringNotification, I stop this new run
loop again. Below is the (abbreviated) code.
Please tell me if that use of CFRunLoop is ok?
- (NSArray *)textView: (NSTextView *)textView
completions: (NSArray *)words
forPartialWordRange: (NSRange)charRange
indexOfSelectedItem: (int *)index
{
// get the current word. That will be the keyword in our query
NSString *word = [[textView string] substringWithRange: charRange];
...
// construct the objects needed to perform the query
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
...
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(queryHandler:)
name: NSMetadataQueryDidFinishGatheringNotification
object: query];
[query startQuery];
// start a new run loop, efffectively halting at this point
CFRunLoopRun();
return [self suggestions];
}
- (void)queryHandler: (NSNotification *) inNotification
{
NSMetadataQuery *query = [inNotification object];
// do something with the query
[self setSuggestions: suggestions];
// stop the run loop again
CFRunLoopStop(CFRunLoopGetCurrent ());
}
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden