In my viewController i create an instance of the class QuestionParser which will start a xml parser. My question is: IS there the possibility so the parser will not finish parsing before the program reaches compblock, thus returning nil argument or even an error ?
MenuViewController.m
QuestionParser *parser = [[QuestionParser alloc]init];
[parser parseCategories:^(NSArray *categoryName, NSArray *categoryID)
{
if(categoryName)
{
NSlog(@"%@",categoryName);
}
}];
QuestionParser.m
(void) parseCategories:(myCategoryCompletion) compblock {
[self parseCategories];
compblock(categoryName,categoryID);
}
I am sorry i didn't provide all the info, and i will try to clarify the situation. in parseCategories
function i do this:
-(void) parseCategories {
NSLog(@"<> start parsing categories <>"); categoryParser = [[NSXMLParser alloc]initWithContentsOfURL:[URL]]; [categoryParser setDelegate:self]; [categoryParser parse]; }
And i expect so the completion block does not end before my parser's delegate "didFinishDocument
" reaches. Will this be the case ?
Now, while testing this functions, everything works ok, my parser delegates create the arrays i need from the xml and after that, it reaches the end on the block compblock(categoryName,categoryID) returning to the view controller what i need. I wander if the parser takes to long will it still work ?
You don't need to worry about that. The "parse" of NSXMLParser is synchronous. Unless the completion or failure returns, "parse" will be over.