Reputation: 372
i've got this error after parsing. * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString stringValue]: unrecognized selector sent to instance 0x4b68480'
Code is
-(void)parser: (NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if([elementName isEqualToString:@"gallery"]){
}
else if ([elementName isEqualToString:@"asset"]){
NSString *str ;
str = [[attributeDict objectForKey:@"type"] stringValue]; <- HERE
NSLog(@"type = %@",str);
str = [[attributeDict objectForKey:@"thumbnail"] stringValue]; <- HERE
NSLog(@"thumbnail = %@",str);
str = [[attributeDict objectForKey:@"large"] stringValue]; <- HERE
NSLog(@"large = %@",str);
}
NSLog(@"Processing Element: %@",elementName);
}
XML tree looks like
"<"gallery ...">" "<"asset type="image" thumbnail="/..." large="/..." ">" ...
Thank you for help!
Upvotes: 0
Views: 202
Reputation: 4473
The error tells obviously [attributeDict objectForKey:...]
is returning NSString
already. So, you do not have to call stringValue
to store into str
. i.e., instead of
str = [[attributeDict objectForKey:@"type"] stringValue];
you can just do
str = [attributeDict objectForKey:@"type"];
Upvotes: 0