Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSXMLParser on iOS8 - NSXMLParser does not support reentrant parsing

I have NSXMLParser problem, and i tried iOS8 NSXMLParser crash this topic, but i really did not get the solution.

I am creating another NXSMLParser delegate and setting its delegate in another class.

Could you please tell me what to do exactly, step by step? I am so confused.

Here is my code;

These lines of codes are inside the STXMLParser

   STXMLParser2 *stXMLParser2 = [[STXMLParser2 alloc]init];    

    stXMLParser2.xmlParser = [[NSXMLParser alloc] initWithData:responseLoader.xmlData];
    [stXMLParser2.xmlParser setDelegate:self];
    [stXMLParser2.xmlParser setShouldResolveExternalEntities:YES];
    [stXMLParser2.xmlParser parse];
like image 911
erdemgc Avatar asked Mar 27 '26 05:03

erdemgc


2 Answers

You can try this code:

dispatch_queue_t reentrantAvoidanceQueue = dispatch_queue_create("reentrantAvoidanceQueue", DISPATCH_QUEUE_SERIAL);
    dispatch_async(reentrantAvoidanceQueue, ^{
        STXMLParser2 *stXMLParser2 = [[STXMLParser2 alloc]init];    
        stXMLParser2.xmlParser = [[NSXMLParser alloc] initWithData:responseLoader.xmlData];
        [stXMLParser2.xmlParser setDelegate:self];
        [stXMLParser2.xmlParser setShouldResolveExternalEntities:YES];
        [stXMLParser2.xmlParser parse];
    });
    dispatch_sync(reentrantAvoidanceQueue, ^{ });
like image 64
rozochkin Avatar answered Mar 29 '26 22:03

rozochkin


I was getting the same error and it turned out that the problem was due to calling a UI update in the func parserDidEndDocument(parser: NSXMLParser) which does not run on the main thread. After forcing the UI update in that function to run on the main queue, the problem was resolved.

like image 40
RawMean Avatar answered Mar 29 '26 22:03

RawMean