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.

162 CHAPTER 7 Protocols<br />

Listing 7.16<br />

Parser output<br />

Parser_Project[57815:207] Started Element Author<br />

Parser_Project[57815:207] Started Element name<br />

Parser_Project[57815:207] Found an element named: name with a value of:<br />

Collin Ruffenach<br />

Parser_Project[57815:207] Started Element age<br />

Parser_Project[57815:207] Found an element named: age with a value of: 23<br />

Parser_Project[57815:207] Started Element gender<br />

Parser_Project[57815:207] Found an element named: gender with a value of:<br />

male<br />

Parser_Project[57815:207] Started Element Books<br />

Parser_Project[57815:207] Started Element Book<br />

Parser_Project[57815:207] Started Element title<br />

Parser_Project[57815:207] Found an element named: title with a value of:<br />

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

Parser_Project[57815:207] Started Element year<br />

Parser_Project[57815:207] Found an element named: year with a value of: 2010<br />

Parser_Project[57815:207] Started Element level<br />

Parser_Project[57815:207] Found an element named: level with a value of:<br />

intermediate<br />

Parser_Project[57815:207] Found an element named: Book with a value of:<br />

intermediate<br />

Parser_Project[57815:207] Found an element named: Books with a value of:<br />

intermediate<br />

Parser_Project[57815:207] Found an element named: Author with a value of:<br />

intermediate<br />

You can see that, using the NSXMLParser delegate methods, you successfully parsed all<br />

of the information in your XML file. From here you could create <strong>Objective</strong>-C objects<br />

to represent the XML and use it throughout your application. XML processing is a vital<br />

part of most applications that get their content from some kind of web source: Twitter<br />

clients, News clients, or YouTube.<br />

7.4 Summary<br />

Protocols are regularly seen when developing using UIKit and Core Foundation for<br />

the iPhone. They’re one of the foundation design decisions for most of the classes<br />

Apple provides. With attentive coding, protocols can make your application efficient<br />

and error proof.<br />

We looked at defining your own protocol for a variety of reasons, conforming to<br />

protocols, and some specific popular protocols from the iPhone SDK. These protocols<br />

are also great to use when creating code you want to reuse. Through a proper understanding<br />

and implementation of the protocol design method, you can ensure a welldesigned<br />

application.<br />

In chapter 8, we look at how you can define your classes to have dynamic typing.<br />

Dynamic typing is an important principle to apply when considering memory for your<br />

applications. It’s used in many protocol implementations, and a good grasp of<br />

dynamic styping will further your understanding of protocol design.

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

Saved successfully!

Ooh no, something went wrong!