What We’ve Learned

In this chapter, we dug into one of the most common tasks for any iOS app: fetching data from the network and parsing it into native Swift types. We started by using URLSession to fetch the contents of a URL into a Data object, on a queue of our choice (or, by default, a background queue) so that network activity doesn’t block the main queue that updates the user interface.

Next, we took this data and ran it through the XMLParser, the event-driven parser built in to iOS. While having to manually handle the start, end, and contents of each tag as it’s parsed is rather burdensome, it does let us sift through the XML for just the pieces we want (and saves the memory hit of creating an entire DOM that we might only want a tiny fraction of).

We’ve just scratched the surface of how apps interact with back-end services. When you’re ready to dig further into the topic, Pragmatic Programmers has a whole book available on the topic: iOS Apps with REST APIs [Mou16] by Christina Moulton.

Now that we have a PodcastFeed object with an array of PodcastEpisodes, we’re ready to present the actual podcast feed in our app’s user interface. In the next chapter, we’ll see how UIKit tables provide the natural interface for doing just that.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset