IPhone application freezes when parsing XML

My application freezes whenever I parse an XML feed.

I tried this instead:

[NSThread detachNewThreadSelector:@selector(parseXML) toTarget:self withObject:nil];

which causes:

-(void) parseXML {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [self parseXMLFileAtURL:path];
    [pool drain]; 
}

but my application became rather unstable as a result ... iPhone Simulator just crashed without warning an error.

+3
source share
1 answer

Instead of calling:

[NSThread detachNewThreadSelector:@selector(parseXML) toTarget:self withObject:nil];

you should call:

[self performSelectorInBackground:@selector(parseXML) withObject:nil]

Your user interface freezes because you are doing lengthy operations in the user interface thread.

+2
source

Source: https://habr.com/ru/post/1729977/


All Articles