I have seen many samples of NSXMLParser and understand how it works. For example, this one is very good:
http://wiki.cs.unh.edu/wiki/index.php/Parsing_XML_data_with_NSXMLParser
All samples I saw use Release to release temporary objects at some point during parsing which is OK. But if I switch on ARC, I don’t have access to release at all. How does the sample code change then?
For example, please look at the above code (link) and explain how would you change it with ARC ON?
Thanks.
For a discussion of how one goes about making non-ARC code enabled with ARC, I’d refer you to the Transitioning to ARC Release Notes. As Midhun alludes, you will be replacing
retainreferences withstrongreferences and eliminatingreleaseandautorelease. You’ll also be removing calls to[super dealloc]. So the conversion isn’t hard, but there are a number of items to be conscious of.Having said that, I disagree with your assessment that this example code is “pretty good.” With no insult to the original author, it’s a little outdated, and as such, is applying historical conventions rather than the modern contemporary practice (e.g. explicitly declared ivars for properties, not using underscore for ivar names, etc.). I also noticed a few bugs in the code (minor things like a missing property, more significant things like a bug in the
foundCharactersroutine, etc.).I’ve cleaned up the code (both converting it to ARC and addressing a number of these issues) and have uploaded it to a repository on GitHub. Note, I’ve done two things:
I’ve modified the code to be a little more contemporary in its practices (this is the
UsersParserclass) and fixing a few of these little bugs;I’ve also made a rendition of this code which is a little more flexible, the
XmlArrayParser, where the parser class isn’t hard-coded for the Users XML file that the example uses. The method that calls this has to understand what elements we’re looking for, but the parser itself doesn’t care.I hope this help.