Created
April 10, 2012 13:07
-
-
Save iKenndac/2351239 to your computer and use it in GitHub Desktop.
Observing SPSearch with KVO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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