NSObject子类中的NSXMLParser切换线程

发布于 2024-10-10 03:45:15 字数 1509 浏览 4 评论 0原文

我刚刚创建了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑寡妇 2024-10-17 03:45:15

您还会在什么地方使用它?除了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文