通过发送请求和实现NSOperationQueue的实现在数据库中并行存储响应 [英] Implementation of NSOperationQueue by sending request & Storing response in Database parallely

查看:98
本文介绍了通过发送请求和实现NSOperationQueue的实现在数据库中并行存储响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了NSOPERATIONQUEUE通过发送请求,我可以从服务器下载响应,但问题是我无法并行处理sqlite插入/更新响应,我得到数据库锁定错误。所以任何人都可以建议我使用数据库插入/更新我的下载响应的解决方案??

I have implemented NSOPERATIONQUEUE By sending request and i can able to download response from server but the problem is i cant able to parallely process the sqlite to insert/update the response,i am getting Database Locked Error.So Can anyone suggest me a solution to work with database for insertion/updation of my downloded response??

推荐答案

必须使用GCD在主线程中运行所有数据库命令。在ios中同步下载和主线程是一种常见的模式。



you must use GCD to run all databse commands in the main thread. It is a common pattern in ios to syncronize download and main thread.

dispatch_async(dispatch_get_main_queue(), ^{
 // your do stuff
});





这是一个很好的教程来自Ray Wenderlich。



Here is a nice tutorial from Ray Wenderlich.


这篇关于通过发送请求和实现NSOperationQueue的实现在数据库中并行存储响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆