XML and manually building XML documents

Since we are unable to use the NSXMLNode, NSXMLDocument, and NSXMLElement classes in iOS projects, we generally need to manually build the XML string or use third-party libraries. This method is error-prone and it requires us to have a very good knowledge of how XML documents are built but, if we are careful, we can create simple XML documents this way.

Let's see how to manually create an XML document. For this, we will create a function named builXMLString(), which takes an array of Book objects as its only parameter. We will also create a helper class named getElementString() that will create a string representation of an XML element. The getElementString() function will accept two elements: the element ...

Get Mastering Swift 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.