NSObject子类中的NSXMLParser切换线程
我刚刚创建了 NSObject 的一个子类,它初始化 NSXMLParser,解析 XML,然后调用我传递给子类的委托中的方法:
Initialiser:
- (id)initWithData:(NSData *)data interestingKeys:(NSSet *)interestingKeys_
itemElm:(NSString *)itemElement_ delegate:(id <XDelegate>) delegate_
{
if((self = [super init])) {
self.delegate = delegate_;
//create parser and start parsing
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
[parser release];
}
return self;
}
Call method in delegate:
- (void) parserDidEndDocument:(NSXMLParser *)parser
{
//calls parserDidFinishParsingData: in delegate class
[self.delegate parserDidFinishParsingData:self.arrayOfDictionaries];
}
然后,我可以获取解析的数据(存储在 self.arrayOfDictionaries 中)并在委托类中使用它。
问题是,我收到以下日志消息:
[Switching to thread 11523]
[Switching to thread 11523]
我将 NSXMLParser 活动放入 NSObject 子类中是否会给自己带来问题?
DDXMLParser.h: https://gist.github.com/762235
DDXMLParser.m: https://gist.github.com/762236< br> 用例: https://gist.github.com/762237
干杯
I have just created a subclass of NSObject which initialises an NSXMLParser, parses XML and then invokes a method in the delegate I pass to the subclass:
Initialiser:
- (id)initWithData:(NSData *)data interestingKeys:(NSSet *)interestingKeys_
itemElm:(NSString *)itemElement_ delegate:(id <XDelegate>) delegate_
{
if((self = [super init])) {
self.delegate = delegate_;
//create parser and start parsing
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
[parser release];
}
return self;
}
Call method in delegate:
- (void) parserDidEndDocument:(NSXMLParser *)parser
{
//calls parserDidFinishParsingData: in delegate class
[self.delegate parserDidFinishParsingData:self.arrayOfDictionaries];
}
I am then able to take the parsed data (which is stored in self.arrayOfDictionaries
) and use it in the delegate class.
The problem is, I get the following log messages:
[Switching to thread 11523]
[Switching to thread 11523]
Am I causing problems for myself by placing the NSXMLParser activity into an NSObject subclass?
DDXMLParser.h: https://gist.github.com/762235
DDXMLParser.m: https://gist.github.com/762236
Use case: https://gist.github.com/762237
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还会在什么地方使用它?除了 C 函数之外,还可以是根类或另一个根类的子类。
从您自己的自定义 Cocoa 对象创建和使用 Cocoa 对象没有任何问题。
日志消息读起来就像来自调试器,与您对 NSXMLParser 的使用无关。调试器是否中断了您的应用程序?如果是这样,请查看它并看看它说了什么。
Where else would you use it from? Besides a C function, a root class, or a subclass of another root class.
There's nothing wrong with creating and using Cocoa objects from your own custom Cocoa objects.
The log messages read like they came from the debugger, and have nothing to do with your use of NSXMLParser. Did the debugger interrupt your application? If so, look in it and see what it says.