简体   繁体   English

FMDatabase和NSOperation

[英]FMDatabase and NSOperation

I am using FMDatabase for sqlite based iphone application. 我正在将FMDatabase用于基于sqlite的iPhone应用程序。 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]. 问题在于应用程序正在从Web服务中获取批量数据,并将其插入阻止UI [主线程]的本地sqlite数据库中。 Also we cannot run sqlite related commands in background thread. 同样,我们无法在后台线程中运行与sqlite相关的命令。 Can we use NSOperation here ? 我们可以在这里使用NSOperation吗? 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. 只要您仅在该线程中而不是从主线程或任何其他线程中运行它们,您就应该能够在后台运行SQLite操作。

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. 您可以使用NSOperationQueue来处理此问题,将并发操作的最大数量设置为1,以确保一次只写入一次SQLite,然后调用NSInvocationOperations来保存数据。

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

[operationQueue addOperation:invocation];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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