tags:

views:

30

answers:

2

How to parse xml without freezing GUI in iphone SDK ?

during parsing user can interact with gui components. But as i have seen most of the times GUI become freeze when xml parsing performed.

+3  A: 

Move parsing to the background thread, the easiest way will be to call:

[someObject performSelectorInBackground:@selector(parse) withObject:nil];

Remember that each thread requires separate NSAutoreleasePool for proper memory management so you will need to create it in the beginning of the parse method and drain in the end:

- (void) parse{
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   ...
   [pool drain];
}
Vladimir
But i have a bit of complicated situation like:
Matrix
[self performSelectorInBackground:@selector(CustomMethod:) withObject:nil];-(void)CustomMethod:(id)sender{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; ObjXMLWebService = [[XMLWebService alloc]initWithSoapElements:[NSDictionary dictionaryWithObjectsAndKeys:@"value",@"Key",nil] BodyTitle:@"TitleOfXMLWebService" BodyAction:URLValue xsi:URLValue xsd:URLValue soap:URLValue Version:VersionNumber Encoding:EncodingUsed];ObjXMLWebService.theRequest = [ObjXMLWebService ConfigureRequestWithContentType:ContentTypeValue SOAPAction:SoapActionValue To:URLValue];
Matrix
[ObjXMLWebService ConnectWithRequest:ObjXMLWebService.theRequest]; [pool drain];}-(void)ConnectWithRequest:(NSMutableURLRequest*)req{............Connection=[[NSURLConnection alloc]initWithRequest:theRequest delegate:XMLConnection];XMLConnection defines connection delegate methods, which also calls/sets another class for parsing delegate methods.
Matrix
A: 

Just as Vladimir mentioned, the background thread is the way to go. Check out the Apple sample code called SeismicXML as it does full asynch XML parsing with the NSXMLParser.

stitz