01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

158 CHAPTER 7 Protocols<br />

sets a title here, this button fits the actionSheetCancel: method. It’s commonly red<br />

(you can see it in the contacts section of the iPhone), and is used to confirm actions<br />

such as deleting data or logging off:<br />

- (void)actionSheetCancel:(UIActionSheet *)actionSheet<br />

7.3.4 NSXMLParser<br />

The final protocol we review differs slightly from the protocols we already covered.<br />

Apple provides a class to iPhone developers called NSXMLParser. Developers use this<br />

class when parsing XML. It should be noted that several open source alternatives to<br />

NSXMLParser are available and used by many developers, but for the sake of consistency,<br />

we look at the delegate methods of the standard Cocoa XML Parser.<br />

There is no protocol; you’ll receive no warning if you don’t declare<br />

this in the header of the application you’re creating. NSXMLParser is a fringe design<br />

class that follows the principles of protocol design but doesn’t explicitly define a protocol.<br />

An NSXMLParser object, like the other objects, has a parameter called delegate<br />

that must be defined. Any object defined as the delegate has the option of implementing<br />

and collecting 20 different delegate methods. NSXMLParser provides delegate<br />

methods that handle every point of parsing for both XML- and Document Type Definition<br />

(DTD)-based documents.<br />

XML is a type of file that can hold data in a very structured manner. As a quick introduction,<br />

XML uses syntax similar to HTML in order to create unique data structures. An<br />

example of an XML element to describe a person is shown in the following listing.<br />

Listing 7.10<br />

An author in XML<br />

<br />

Collin Ruffenach<br />

23<br />

male<br />

<br />

<br />

<strong>Objective</strong> C for the iPhone<br />

2010<br />

intermediate<br />

<br />

<br />

<br />

XML is a common means of getting data from online sources such as Twitter. XML is<br />

also used to facilitate the data required to run your specific iPhone project. iOS development<br />

relies heavily on plist files. These files are really just XML and are used by<br />

Xcode to get things like your icon name and other application data. Xcode handles<br />

the setup of these values.<br />

DTD is a document that describes the structure of the XML that you’re working<br />

with. The DTD for the XML in listing 7.10 would be the following:<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!