05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

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.

src='http://www.worldofkevin.com/Site/Blog/Images/FD004359-1.jpg'<br />

style='float:left; padding-right:10px; padding-bottom:10px; width:109px;<br />

height:79px;'/>&lt;/a>Eliquatuero dip numsan vent lam, conum facillum init lut<br />

doloreet ullametuero od tet adit, commod tatummy feug tiam velit praese exer aute<br />

enit alit, veliqua modit dolorer commod niam onul laore. Uptat prat lut lut<br />

iriliquat, quis alisl irilit am irillum at niam zzrit, verosto consequ ismodit<br />

irius<br />

<br />

<br />

<br />

<br />

<br />

If you speak XML, it’s pretty easy to see what’s going on here, because the XML tags are on<br />

separate lines and indented to show what goes where. However, if we tried to log this node, NSLog<br />

would simply call [NSXMLNode description] behind the scenes and produce an unreadable mess.<br />

NSXMLNode *xmlNode;<br />

// ... load the XML document<br />

NSLog(@"Current node: %@", xmlNode);<br />

Current node: My Bloghttp://www.worldofkevin.com/Site/Blog/Blog.htmlWelcome to my blog: Alit, Enit, Laore, Eros Vel, Exer Dolorer, Niam Lut<br />

.iWeb 1.1.2http://www.worldofkevi<br />

n.com/Site/Blog/Blog_files/200206373-3-a.pngMy Bloghttp<br />

://www.worldofkevin.com/Site/Blog/Blog.htmlRed Vines:<br />

the perfect super foodhttp://www.worldofkevin.com/Site/Blog/88DD8356<br />

-E484-44DD-9419-AE9F936E8BAD.htmlhttp://www.worldofkevin.com/Site/Blo<br />

g/88DD8356-E484-44DD-9419-AE9F936E8BAD.htmlMon, 20 Aug 2007 10:48:<br />

11 -0700&lt;a href='http://www.worldofkevin.com/Site/Blog/8<br />

8DD8356-E484-44DD-9419-AE9F936E8BAD_files/FD004359-1.jpg'>&lt;img src='http://www.<br />

worldofkevin.com/Site/Blog/Images/FD004359-1.jpg' style='float:left; padding-right<br />

:10px; padding-bottom:10px; width:109px; height:79px;'/>&lt;/a>Eliquatuero dip num<br />

san vent lam, conum facillum init lut doloreet ullametuero od tet adit, commod tat<br />

ummy feug tiam velit praese exer aute enit alit, veliqua modit dolorer commod niam<br />

onul laore. Uptat prat lut lut iriliquat, quis alisl irilit am irillum at niam zzr<br />

it, verosto consequ ismodit irius<br />

Yuck! All the whitespace is gone, and everything is just run together. It’s possible, by other<br />

means, to output a node using pretty printing to make it more readable, but I always forget. It<br />

would be a lot more convenient if description would always apply pretty printing.<br />

To accomplish this, we’ll create a category on NSXMLNode that defines a new method and then<br />

swap that method’s implementation with the existing one:<br />

#import <br />

#import <br />

@interface NSXMLNode (BMPrettyDescriptions)<br />

- (NSString *)prettyDescription;<br />

@end<br />

@implementation NSXMLNode (BMPrettyDescriptions)<br />

CHAPTER 26 MAC <strong>OS</strong> X DEVELOPMENT: OBJECTIVE-C 501

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

Saved successfully!

Ooh no, something went wrong!