TBXMLSuccessBlock
and TBXMLFailureBlock
are used as an efficient way for implementing conditions for successful and unsuccessful retrieval of the XML data from the given URL. Look at Apple's Blocks programming guide for more in-depth information about Objective-C blocks.
If you just want some example code on how to use it, here it is (using the latest version of TBXML):
TBXMLSuccessBlock s = ^(TBXML *tbxml) {
NSLog(@"yay");
// Do something with TBXML object "tbxml
// ...
// An example - print the name of an element
TBXMLElement *e = [TBXML childElementNamed:@"head" parentElement:tbxml.rootXMLElement];
NSString *a = [TBXML elementName:e];
NSLog(@"%@",a);
};
TBXMLFailureBlock f = ^(TBXML *tbxml, NSError *error) {
// Do something to recover from the failure here
// ....
NSLog(@"nay");
};
[TBXML newTBXMLWithURL:[NSURL URLWithString:@"http://www.google.co.nz"]
success: s
failure: f];
When you execute this code, TBXMLSuccessBlock should execute if you have access to the following URL. If you can't reach the website, the TBXMLFailureBlock will execute.
As a side note, if a library you are using is non-ARC (assuming the library is source code and not a static or dynamic library ) and you are trying to integrate it into ARC-ified source, you can do this under Xcode by going to your xcodeproj file -> Build Phases -> Compile sources and for each .m file that does not use ARC, enter the compiler flag -fno-objc-arc
which will tell the compiler not to compile it with ARC.