views:

419

answers:

1

Hey guys,

I have been looking for hours and didn't find anything so I decided to give up and ask for your precious knowledge ;)

In order to make my code cleaner, I would like to implement the delegate methods of NSXMLParser in another file ... but I couldn't find any tutorials ...

Could someone explain me briefly how to do that ?

Cheers mates,

Gauthier.

+1  A: 

Create a Class that implements the methods you want your parser to respond to, then set the delegate of your NSXMLParser instance to an instance of your new Class.

Rob Jones
As my delegate instance will not be retained by my parser, where am i supposed to release it ? In dealloc ? Thanks for the help ;)
gotye
One more question : what type is supposed to be my delegate class ?nsobject ?!? Or what ?Cheers
gotye
Make the delegate class inherit from NSObject.
Rob Jones
It's hard to say where you should release your delegate instance. That depends on your code and a lot of things that are not easily answered in comments. I suggest reading up on iPhone memory management. But yeah, dealloc() is an option, but not necessarily the right option.
Rob Jones
Ok, i think i got it ;) last thing i was thinking about is whether it was better to create a subclass of nsxmlparser (and set self as delegate) or to create a delegate ... Thanks a lot for your time !
gotye
I think I can argue either way; depends on what you're doing. If your delegate implements methods that would be useful in other instances of NSXMLParser, than it make sense to use a distinct delegate. But, if you're just doing this once, and can never conceive of reusing these methods, then subclassing NSXMLParser would be just fine. I would lean towards a separate delegate object since it's more flexible.
Rob Jones
Well, thanks A LOT for all these information ;) !
gotye