Is NSXMLParser's parse method asynchronous

前端 未结 4 538
清酒与你
清酒与你 2021-02-14 08:29

Is NSXMLParser\'s parse method asynchronous?

in other words if i have an NSXMLParse object and I call [someParseObject parse] from the main thread, will it

4条回答
  •  旧时难觅i
    2021-02-14 09:28

    you can do like this NSXMLParser as asynchronous

    dispatch_async( dispatch_get_global_queue(0, 0), ^{
    
        NSString * dovizUrl=@"http://www.tcmb.gov.tr/kurlar/today.xml";
        NSURL *url = [NSURL URLWithString:dovizUrl];
        NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
        xmlParser.delegate = self;
        // call the result handler block on the main queue (i.e. main thread)
        dispatch_async( dispatch_get_main_queue(), ^{
            // running synchronously on the main thread now -- call the handler
            [xmlParser parse];
        });
    });
    

提交回复
热议问题