Starting my first iOS project and wanted to advice on how to structure the application.
The app pulls a XML feed, parses it out and displays a list representing the items in the XML feed. When clicking on a item in the list the app will pull a new XML feed using one of the attributes from the previously pulled XML feed. This happens several layers of pull, parse, display and on user selection do the same thing over again. Now most of the XML element structure is something like this:
(These are simple examples just to demonstrate what’s going on)
returns (Display info on new view):
<items>
<item id="123" name="item 1" />
<item id="124" name="item 2" />
<item id="125" name="item 3" />
</itmes>
- http://site.com/get/description/123 (Example user has selected item 1, make call to get description)
returns:
<itemDescription>
<description itemId="123" name="desc 1" description="blah 1" />
</itemDescription>
Wanted to know:
- Should I have a connection class/object or a new connection in each view?
- Should I have a parser class/object or parse the XML feed in each view?
- I’m also looking to store some of the data returned so I don’t need to call the XML feed again if the user navigates back to the main items list, but I would need to parse the itemsDescription XML feed every time.
I’ve looked at several tutorials on parsing XML and I get the gist of how to do this, wanting to focus more of the design and reusability instead of duplicating the code over in each new view. Or am I way off on how this works
The best way you can do this following Apple Guidelines is checking one of their examples, some months ago I made an app similar to yours following this example. Also you can see how to make your app in offline mode.
Basic structure (w/o offline mode):
Advanced structure (with offline mode):
Regarding cwieland answer I wouldn’t use ASIHTTPRequest because is outdated, so if you want to follow his approach I would recomend you to use AFNetworking, where you can handle an XML request easy and fast: