简体   繁体   中英

FMDatabase and NSOperation

I am using FMDatabase for sqlite based iphone application. The problem is that application is fetching bulk data from a web service and inserting into a local sqlite database which is blocking UI [main thread]. Also we cannot run sqlite related commands in background thread. Can we use NSOperation here ? Any example ??

You should be able to run your SQLite operations in the background, as long as you only run them inside that thread and not from the main or any other.

You could use a NSOperationQueue to handle this, setting the max number of concurrent operations to 1 to make sure only one writes to your SQLite at a time and then calling NSInvocationOperations to save your data.

NSInvocationOperation * invocation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(writeThisToDB) object:thisObject];

[operationQueue addOperation:invocation];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM