dianovich
dianovich

Reputation: 2287

NSXMLParser in NSObject subclass switching threads

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

Upvotes: 0

Views: 568

Answers (1)

Peter Hosey
Peter Hosey

Reputation: 96363

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.

Upvotes: 1

Related Questions