如何在iOS 7中解析xml并同时异步保存到sqlite?
我正在使用如何在iOS 7中解析xml并同时异步保存到sqlite?,sqlite,asynchronous,xml-parsing,ios7,nsnotifications,Sqlite,Asynchronous,Xml Parsing,Ios7,Nsnotifications,我正在使用TBXML解析XML文档,但我必须解析XML并使用通知异步地将数据存储到SQLite[即在SQLite中解析和存储数据]。请帮助我克服这个问题。提前感谢……您可以使用NSNotificationCenter和GCD 首先为您的流程设置NSNotificationCenter,使用 [[NSNotificationCenter defaultCenter] addObserver:self sel
TBXML
解析XML文档,但我必须解析XML并使用通知异步地将数据存储到SQLite[即在SQLite中解析和存储数据]。请帮助我克服这个问题。提前感谢……您可以使用NSNotificationCenter
和GCD
首先为您的流程设置NSNotificationCenter,使用
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dataStore)
name:@"dataStoreComplete" object:nil];
- (void)dataStore
{
NSLog(@"Received Notification - Data stored in databse");
}
您可以使用GCD进行解析并存储在数据库中
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// switch to a background thread and perform your expensive operation
// parse and store all data in sqlite,
dispatch_async(dispatch_get_main_queue(), ^{
// switch back to the main thread to update your UI
[[NSNotificationCenter defaultCenter] postNotificationName:@"dataStoreComplete" object:nil];
});
});
到目前为止,您尝试了什么?@Virussmca我清楚地提到,我解析了数据并将其存储到数据库中,但XML字符串包含图像链接,我也必须将其存储到数据库中。我不想阻塞我的主线程。请帮助我它的紧急…我将首先添加您的,并看到结果,然后我将接受您的回答。。。