Skip to content

Instantly share code, notes, and snippets.

@kuetsuhara
Created December 27, 2013 07:29
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 kuetsuhara/8143715 to your computer and use it in GitHub Desktop.
Save kuetsuhara/8143715 to your computer and use it in GitHub Desktop.
//まずはプロパティを宣言
@property (nonatomic, strong) CBLLiveQuery *liveQuery;
//ViewDidLoadに以下を追加します。
AppDelegate *ap = ApplicationDelegate;
self.liveQuery = [[ap.database queryAllDocuments] asLiveQuery];
[self.liveQuery addObserver:self forKeyPath:@"rows" options:0 context:NULL];
//そして、以下を追加。
//(レプリケーションを追加していれば、すでにあるものの中にif文を追加する)
- (void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (object == self.liveQuery) {
NSLog(@"live query”);
// ライブクエリ時の処理をここに書く
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment