On May 18, 2014, at 6:33 AM, Ragu Vijaykumar <
ra...@scrxpt.com> wrote:
> 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];
> });
There are a couple of things wrong here —
1. The shared instance of CBLManager should only be used on a single thread (usually the main thread.)
2. There’s an existing method -[CBLManager backgroundTellDatabaseNamed:to:] to run code on a background thread, so you don’t need to go through the work.
3. Even if you do that, this code won’t do anything because the background thread’s database instance doesn’t have any CBLModels.
Unfortunately there isn’t really a clean way to do what you’re asking, yet. An implementation of this would need to collect the -propertiesToSave from each modified CBLModel, send that data to the background thread and save the properties to the corresponding CBLDocuments, and then back on the main thread mark the models as unmodified as soon as the change notification arrives. The last step in particular is tricky and I don’t think it can be done with the public API.
Are you having performance problems saving? If so I’d love to see some profile data from Instruments.
—Jens