Weird Errors


Hi there

I’m not sure what I’m missing but I’m getting this error when I run my iTunes Top Songs example… it seems like when I pass the string “Itunes Store: Top Songs” if barfs… but I dont understand why.

I can step through the code and this is indeed where it fails… any thoughts?

- (void) parser:(NSXMLParser *)parser 
foundCharacters:(NSString *)string{
	NSLog(@"Appending String:%@",string);
	[titleString appendString:string]; // this line fails

[code]2011-04-07 17:30:02.170 TopSongs[24436:207] Got some more data!
2011-04-07 17:30:02.211 TopSongs[24436:207] Got some more data!
2011-04-07 17:30:02.213 TopSongs[24436:207] Appending String:
Current language:  auto; currently objective-c
2011-04-07 17:30:24.207 TopSongs[24436:207] titleString:(null)
2011-04-07 17:30:49.385 TopSongs[24436:207] Appending String:
2011-04-07 17:31:09.844 TopSongs[24436:207] titleString:(null)
2011-04-07 17:31:15.692 TopSongs[24436:207] ***found a title***
2011-04-07 17:31:15.697 TopSongs[24436:207] Appending String:iTunes Store: Top Songs
2011-04-07 17:31:18.376 TopSongs[24436:207] -[NSConcreteMutableData appendString:]: unrecognized selector sent to instance 0x5923160
2011-04-07 17:31:18.379 TopSongs[24436:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData appendString:]: unrecognized selector sent to instance 0x5923160'
*** Call stack at first throw:


Notice the exception says the following:

Which means, the appendString: message was sent to an instance of NSConcreteMutableData. Unfortunately, there is a design pattern called class clusters (which you can read up on in the documentation, because it is too large of a topic for me to cover here) that means you will occasionally get instances of classes you have never heard of before.

This is one of those cases, NSConcreteMutableData is really just an instance of NSMutableData. Thus, in your code, titleString is actually an instance of NSMutableData.

Of course, you are concerned. You have it declared in your class interface as NSMutableString, so it must be a NSMutableString, right? Nope - variable types are just hints to the compiler. An object knows its real type. Check out the line where you create the object that titleString points to - in parser:didStartElement:. I bet you have this:

Change it to



You are 100% correct. Thank you. :slight_smile: