You will have to instantiate the models again on the background thread. This is what I do, it's very simple anyway with [MYModel modelForDocument:row.document] (or the factory class). Just pass in document ids, I do that on an export task that runs in a background queue and base64 encodes image attachments, so this may run a while but doesn't block the UI.
On Monday, May 19, 2014 8:51:25 AM UTC-4, Ragu Vijaykumar wrote: > > Yeah, but even if I make the copied CBLManager on the main thread, the > models I have on the main thread won't be accessible through that > background CBLManager. I'm wondering if there is a way to resolve that? > > On Sunday, May 18, 2014 8:43:46 AM UTC-7, Pascal wrote: >> >> No, this is not good. The documentation I linked you to, more >> specifically >> http://docs.couchbase.com/couchbase-lite/cbl-ios/#create-a-background-cblmanager, >> mentions that you should NOT call `sharedInstance` on a background >> thread. Use the example provided and see if that works for you. >> >> On Sunday, May 18, 2014 9:33:54 AM UTC-4, Ragu Vijaykumar wrote: >>> >>> So, this is safe to call even if all my models were created / accessed >>> on the main thread? >>> >>> dispatch_async(dispatch_get_global_queue( >>> DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ >>> >>> NSError* error; >>> >>> CBLDatabase* database = [[[CBLManager sharedInstance] copy] >>> existingDatabaseNamed:@"mydatabase" error:&error]; >>> >>> [database saveAllModels:&error]; >>> >>> }); >>> >> -- 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/42fcb640-b648-49bf-965f-f7cfa7acacde%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
