From c9eaa1a15d2b8a85032ba6745d4023f587112c7f Mon Sep 17 00:00:00 2001 From: Vincil Bishop Date: Sun, 5 Jul 2015 19:16:52 -0500 Subject: [PATCH] Updated for more convenience methods --- .../Classes/NSXMLParser+ReactiveCocoa.h | 16 ++++++++++++++++ .../Classes/NSXMLParser+ReactiveCocoa.m | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.h b/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.h index 189af5c..88b81f6 100644 --- a/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.h +++ b/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.h @@ -73,4 +73,20 @@ typedef BOOL (^ElementFilterBlock)(NSString *elementName); + (RACSignal *)rac_dictionaryFromString:(NSString *)string elementFilter:(ElementFilterBlock)filterBlock; +/** + * Parse a XML using a pre-init'ed parser. + * + * @return RACSignal Will 'next' exactly once, with a NSDictionary parameter + */ +- (RACSignal *)rac_parser; + +/** + * Parse a XML using a pre-init'ed parser. + * + * @param filterBlock ElementFilterBlock (optional) Enables filtering on an element-name level + * + * @return RACSignal Will 'next' exactly once, with a NSDictionary parameter + */ +- (RACSignal *)rac_parserWithElementFilter:(ElementFilterBlock)filterBlock; + @end diff --git a/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.m b/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.m index aca2e39..a2515de 100644 --- a/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.m +++ b/ReactiveNSXMLParserLib/ReactiveNSXMLParserLib/Classes/NSXMLParser+ReactiveCocoa.m @@ -58,6 +58,16 @@ + (RACSignal *)rac_dictionaryFromData:(NSData *)data elementFilter:(ElementFilte return [self rac_dictionaryFromSignal:[self rac_parseData:data] elementfilter:filterBlock]; } +- (RACSignal *)rac_parser +{ + return [NSXMLParser rac_parseWithParser:self]; +} + +- (RACSignal *)rac_parserWithElementFilter:(ElementFilterBlock)filterBlock +{ + return [NSXMLParser rac_dictionaryFromSignal:[self rac_parser] elementfilter:filterBlock]; +} + #pragma mark - Internal /**