I've been following the example code in 
http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/query/index.html

- (void) initializeQuery {
    // Set up my live query during view initialization:
    CBLQuery* query = [[self.db viewNamed: @"widgets"] createQuery];
    query.limit = 100;
    self.liveQuery = query.asLiveQuery;
    [self.liveQuery addObserver: self forKeyPath: @"rows"
                        options: 0 context: NULL];
    [self.liveQuery start];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary *)change
                       context:(void *)context 
{
    if (object == self.liveQuery) {
        [self displayRows: self.liveQuery.rows]; // update the UI
    }
}


My code is slightly different in that:

   1. I get the query from CBLModel subclass. 
   2. addObserver method is called in viewDidLoad

I've been using break point to track debug the code, but observeValueForKeyPath 
is not called.

I've also tried to run the query manually like below, it works.

    CBLQueryEnumerator* result = [self.liveQuery run: &error];
    for (CBLQueryRow* row in result) { 

        NSLog(@"found a row for mssession: %@, %@", row.key, row.value); 

    }

Since both row.key and row.value are up to date, I believe the query itself 
is valid. It's just that the observeValueForKeyPath was never called.
So, there must be something else needed for wiring this up.  Are there any 
assumptions made for using LiveQuery?

And the whole picture was a queue structure, the users are producers or 
consumers. 
To make it concrete, I am trying to maintain a doc which contains an array. 
And this array needs to be modified by different users simultaineously. So 
I need every user to monitor whether this doc is changed. 

I guess there must be some best practice for this. Anyone please lend a 
hand.


-Sean



-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/39f03812-d097-4e9d-9fbc-630cc10bfb4c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to