2

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];
Community
  • 1
  • 1
erdemgc
  • 1,701
  • 3
  • 23
  • 43

3 Answers3

16

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, ^{ });
rozochkin
  • 679
  • 1
  • 7
  • 18
  • 1
    @JackSolomon If you are using a bunch of different `NSXMLParser` instances, you need to fix the case where you're calling `parse` for an `NSXMLParser` in a delegate callback from another `NSXMLParser`. This answer didn't fix my problem until I figured that little bit out. – mbm29414 Oct 25 '14 at 13:27
  • Worked for me. Thanks! – DocAsh59 Jul 25 '17 at 14:29
2

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.

RawMean
  • 8,374
  • 6
  • 55
  • 82
0

I encountered the same problem recently but it turned out that I had an exception in one of my delegates (KVO problem) and once I fixed that the reentracy error went away. So it might be worth to look for something else if you don't have an obvious multithreading or multiinstance problem.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181