Use CFRunLoopRun to synchronize NSMetadataQuery

simple

May 12, 2008

Cocoa

No Comment

– (NSArray *)completionsForPartialWordRange: (NSRange)charRange indexOfSelectedItem: (int *)index

{

// get the current word. That will be the keyword in our query

NSString *word = [[self string] substringWithRange: charRange];

// construct the query string from this word:

NSString *queryString = @”someQueryString”;

// construct the objects needed to perform the query

NSMetadataQuery *query = [[NSMetadataQuery alloc] init];

NSPredicate *pred = [NSPredicate predicateWithFormat: queryString];

[query setPredicate: pred];

// register the call-back

[[NSNotificationCenter defaultCenter]

addObserver: self

selector: @selector(queryHandler:)

name: NSMetadataQueryDidFinishGatheringNotification

object: query];

[query startQuery];

//start a new run loop

CFRunLoopRun();

// after the new loop is finished, continue by returning the new suggestions:

return [self suggestions];

}

– (void)queryHandler: (NSNotification *) inNotification

{

NSMetadataQuery *query = [inNotification object];

NSArray *suggestions = // create the suggestions array from the query result

[self setSuggestions: suggestions];

// stop the new run loop

CFRunLoopStop(CFRunLoopGetCurrent ());

}

This code was just found on:
http://lists.apple.com/archives/Cocoa-dev/2006/Oct/msg00907.html

Seems to be that the guy also added it to his blog:

http://confuseddevelopment.blogspot.com/2006_10_01_archive.html

The solution looks not very error proved but might someon help…

Related Posts

iPhone OS: Design a nice InApp Purchase View

To get up a nice InAppPurchase View for Appleā€™s AppStore, we first need some good looking buttons: http://code.google.com/p/iphonegradientbuttons/ http://undefinedvalue.com/2010/02/27/shiny-iphone-buttons-without-photoshop/ http://iphonedevelopment.blogspot.com/2010/05/improved-gradient-buttons.html http://stackoverflow.com/questions/422066/gradients-on-uiview-and-uilabels-on-iphone/ There are also some tweaks for the UITableView you might consider using: http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view/ http://stackoverflow.com/questions/986392/programmatically-force-a-uiscrollview-to-stop-scrolling-for-sharing-a-table-view/ more information upcoming…

Read More

iPhone OS: Setup an additional Security Layer

As you might already know the iPhone is itself not that secure that people might think (news is german): http://www.heise.de/security/meldung/Luecke-in-Datenverschluesselung-des-iPhones-1007818.html How do you prevent intrusion of your customers data? As a really pragmatic approach, we can just set up additional encryption for our application data: http://stackoverflow.com/questions/2579453/nsdata-aes-class-encryption-decryption-in-cocoa http://iphonedevelopment.blogspot.com/2009/02/strong-encryption-for-cocoa-cocoa-touch.html http://pastie.org/974094/ So if you use for example core […]

Read More

Leave a Reply