我正在使用以下代码运行解析我的 xml 文件的函数...
dispatch_queue_t queue = dispatch_queue_create("updateQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file.xml"]; } );
dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file1.xml"]; } );
dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file2.xml"]; } );
dispatch_async(queue,^ { [self updateFromXMLFile:@"http://path/to/file3.xml"]; } );
dispatch_barrier_async(queue,^ {
dispatch_async(dispatch_get_main_queue(),^ {
[self setBottomBarToUpdated];
});
});
下面是功能updateFromXMLFile
:
- (BOOL) updateFromXMLFile:(NSString *)pathToFile {
NSURL *url = [[NSURL alloc] initWithString:pathToFile];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
XMLParser *parser = [[XMLParser alloc] initXMLParser];
parser.managedObjectContext = self.managedObjectContext;
[xmlParser setDelegate: parser];
BOOL success = [xmlParser parse];
if(success)
return TRUE;
else
return FALSE;
}
我遇到的问题是此错误消息:***Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSCFSet: 0xc675e10> was mutated while being enumerated.'
我猜它与同时与我的 ManagedObjectContext 混淆的所有进程有关。我不确定如何处理。有任何想法吗?谢谢!