First you need to subclass your NSXMLParser
, add new delegate
property call it subclassDelegate
or something similar, so you can differentiate between the super class's delegate. In init be the delegate of your superclass self.delegate = self
;
respond to the delegate methods and forward the methods that you don't want to override to the self.subclassDelegate
respond to the method that you want to override and override it in your subclass protocol.
Here is the example:
@protocol MyXMLParserDelegate;
@interface MyXMLParser : NSXMLParser<NSXMLParserDelegate>
@property (weak) id<MyXMLParserDelegate> subclassDelegate;
@end
@protocol MyXMLParserDelegate <NSObject>
- (void)parserDidStartDocument:(NSXMLParser *)parser;
// this is the method that you override
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string withObject:(id)object;
@end
Then in .m
@implementation MyXMLParser
- (id)init
{
self = [super init];
if(self) {
self.delegate = self;
}
return self;
}
#pragma mark - repspond to NSXMLParser delegate
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[self.subclassDelegate parser:parser foundCharacters:string withObject:yourObject];
}