On Wednesday, August 31, 2016 at 4:00:27 PM UTC-4, Brendan Duddridge wrote:
>
>
> However, this technique doesn't really work with Couchbase Lite because I 
> cannot access the model objects on the main thread those objects that I 
> fetched on the background thread using the NSOperationQueue.
>

One technique is to create what is known as a view model from each query 
row or CBLite model object. View models are usually subclasses of NSObject 
and have the properties you would use to display search results in our UI, 
such as strings, UIImages, etc. As such, you can pass them between threads. 
The view model would have a documentID property for the original document 
so you could actually retrieve it when the user selects it. For example, 
the view model would contain the display name of the result, possibly an 
thumbnail, etc. Whatever you would normally use to display search rows. 
Another advantage is that if you have a non-homogeneous search you can use 
the same view model class to display the results for multiple document 
types. You could have different initializers for each document type or a 
single initializer that checks the row values / document type and sets the 
properties appropriately. 

So, you would loop though the resulting rows or CBLModels and build view 
models from them, then send them to the main thread for display. You can 
make them immutable or possibility even reuse them if you find the query 
creates a large number of objects. If you can create view models from query 
row values alone, as opposed to CBLModels, you can avoid having to load the 
document at all until the user actually selects it in the search results.  

-- 
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 mobile-couchbase+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/def90032-125c-4062-8895-1da685ffebc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to