0

My app is crashing, any thoughts please? I am parsing the xml in my code, here is the code.

if i removed this line it works fine [listItem setValue:currentElementValue forKey:elementName]; Thanks

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

        if ([elementName isEqualToString:@"channel"]) {
            NSLog(@"found channel");
            app.listArray = [[NSMutableArray alloc]init];
        }
        else if([elementName isEqualToString:@"item"]){
            listItem = [[NewsList alloc] init];
            listItem.title = [attributeDict objectForKey:@"title"];
            listItem.description = [attributeDict objectForKey:@"description"];

        }



    }


    -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
        if (!currentElementValue) {
            currentElementValue = [[NSMutableString alloc] initWithString:string];

        }
        else
            [currentElementValue appendString:string];
    }


    -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
        if ([elementName isEqualToString:@"channel"]) {
            return;
        }

        if ([elementName isEqualToString:@"item"]) {
            [app.listArray addObject:listItem];
            listItem = nil;
        }
        else{
            NSLog(@"element name = %@", elementName);

            [listItem setValue:currentElementValue forKey:elementName];
        }

        currentElementValue = nil;
    }
vincentzvegaz
  • 175
  • 1
  • 7
Paragon
  • 982
  • 2
  • 10
  • 37
  • Please search before posting. – trojanfoe Sep 15 '13 at 19:19
  • @trojanfoe, that question looks different, in my case i placed breakpoint and it works for 4,5 fields and then it crashes. NSLog(@"element name = %@", elementName); [listItem setValue:currentElementValue forKey:elementName]; i can see the element and it comes here multiple times – Paragon Sep 15 '13 at 19:33

1 Answers1

0

Your object listItem is of class NewsList. Since you get the error when you use setValue:forKey:, this class NewsList either has no property with name elementName and instance variable elementName or _elementName, or the setter method setElementName: has not been implemented.
Please check that you have set up your property correctly, e.g. using @property and @synthesize.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116