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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access