Skip to content

Instantly share code, notes, and snippets.

@iKenndac
Created April 10, 2012 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iKenndac/2351239 to your computer and use it in GitHub Desktop.
Save iKenndac/2351239 to your computer and use it in GitHub Desktop.
Observing SPSearch with KVO
// In the header
@property (nonatomic, strong) SPSearch *search;
// In the implementation
@synthesize search;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self addObserver:self forKeyPath:@"search.searchInProgress" options:0 context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"search.searchInProgress"]) {
if (self.search.searchInProgress)
NSLog(@"Search running");
else
NSLog(@"Search not running.");
}
}
-(IBAction)doSearch:(id)sender {
// This will only work if the session is logged in.
self.search = [SPSearch searchWithSearchQuery:@"Hello" inSession:[SPSession sharedSession]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment