- (void) initializeQuery {
// Set up my live query during view initialization:
CBLQuery* query = [[database viewNamed: @"tableChange"] createQuery];
query.limit = 100;
liveQuery = query.asLiveQuery;
[liveQuery addObserver: self forKeyPath: @"rows"
options: 0 context: NULL];
[liveQuery start];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (object == liveQuery) {
NSLog(@"%@",@"Rows have changed");
// update the UI
}
}
- (void)tablesCBView {
NSString *table = @"table";
[[database viewNamed: @"tableChange"] setMapBlock: MAPBLOCK({
id DocType = [doc objectForKey: @"docType"];
if ([DocType isEqualToString:table])
emit (doc,nil);
}) version: @"1"];
}
On Oct 30, 2014, at 8:25 AM, Sandra <txm...@gmail.com> wrote:I'm getting "Assertion failed: Cannot reindex view 'tableChange' which has no map block set'"Would you tell me what I'm doing wrong?
I have some more questions:1) Is there something like CBLUITableSource but for collections?
2) I also tried to set a start key and end key in my query with no success. I want to filter by tableId which is numeric, so let's say I'd like to read documents between tableId = 5 and 10. How can this be done?
3) I need to use this live query in only one of several UIViewControllers. Shall I turn off the live query each time this view is closed and re-opened when the view is loaded again?