views:

112

answers:

3

Hi everyone,

I finally get no leaks in my app but I still manage to get my app to crash from time to time ... it is really rare but it pisses me off ;)

Here is what I get :

2010-05-11 19:36:29.487 Infonul[2457:20b] *** -[NSCFString _setParserError:]: unrecognized selector sent to instance 0x3cddb80

[Session started at 2010-05-11 19:36:29 +0200.]
2010-05-11 19:36:29.487 Infonul[2457:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString _setParserError:]: unrecognized selector sent to instance 0x3cddb80'
2010-05-11 19:36:29.488 Infonul[2457:20b] Stack: (
    9479259,
    2423766587,
    9861179,
    9430646,
    9283266,
    4372334,
    56536,
    4191652,
    4191507,
    12699064,
    12697112,
    12697826,
    12697826,
    12700310,
    12359637,
    9263329,
    9260104,
    825261,
    825458,
    23633923
)

Here is where it seems to fail :

// after having downloaded the file to parse
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        CommentsParserDelegate *commentsParserDelegate = [[CommentsParserDelegate alloc] initWithController:self];
        //commentsParserDelegate.commentController = self;
        commentsParser = [[NSXMLParser alloc] initWithData:self.activeDownload];
        [commentsParser setDelegate:commentsParserDelegate];
        [commentsParser parse]; //last function called before crash
    }

No idea why app crashes and I don't understand what the debugger is trying to tell me :D

Hopefully, someone gets some idea ;)

Thank you.

Gotye.

+2  A: 

The debugger is trying to tell you that you (or, more likely, the framework) are trying to invoke a method called _setParserError on an object of class NSString. There's no such method in NSString.

Seva Alekseyev
Well, as I don't know where it could come from, I gave you the relevant code of my parser. If you get a chance to look at it it would be very enjoyable ;) thanks !
gotye
What's the base class of CommentsParserDelegate?
Seva Alekseyev
Class is NSObject
gotye
A: 

Here is the code of "CommentsParserDelegate.m"

//
//  CommentsParserDelegate.m
//  Infonul
//
//  Created by eef16514f684e5d on 26/03/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CommentsParserDelegate.h"


@implementation CommentsParserDelegate

@synthesize currentElement;
//@synthesize commentController;


- (id)initWithController:(CommentsViewController *)comment {

    if (self = [super init]) {

        commentController = comment;
        months = [[NSArray alloc] initWithObjects:@"Jan.",@"Fév.",@"Mars",@"Avril",@"Mai",@"Juin",@"Juil.",@"Août",@"Sept.",@"Oct.",@"Nov.",@"Déc.",nil];
    }

    return self;
}


- (void)parserDidStartDocument:(NSXMLParser *)parser {

    comments = [[NSMutableArray alloc] init];   
    //currentElement = [[NSString alloc] init];

    currentContent = [[NSMutableString alloc] init];
    currentAuthor = [[NSMutableString alloc] init];
    currentDate = [[NSMutableString alloc] init];
}

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

    self.currentElement = elementName;  

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{


    if ([elementName isEqualToString:@"item"]) {
        // save values to an item, then store that item into the array...

        CommentRecord *comment = [[CommentRecord alloc] init];

        [comment setAuthor:[[[NSString alloc] initWithString:[currentAuthor stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] autorelease]];
        [currentAuthor setString:@""];      

        [comment setContent:[[[NSString alloc] initWithString:[currentContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] autorelease]];
        [currentContent setString:@""];


        NSString *tempDate = [[[NSString alloc] initWithString:[currentDate stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] autorelease];

        NSMutableString *tempString = [[NSMutableString alloc] initWithString:[tempDate substringToIndex:2]];
        NSString *month = [[tempDate substringFromIndex:3] substringToIndex:2];
        [tempString appendString:@" "];
        [tempString appendString:[months objectAtIndex:[month intValue]-1]];
        [tempString appendString:@" "]; 
        [tempString appendString:[[tempDate substringFromIndex:6] substringToIndex:4]];
        [tempString appendString:@" à "];
        [tempString appendString:[[tempDate substringFromIndex:11] substringToIndex:8]];
        [comment setDate:[[[NSString alloc] initWithString:tempString] autorelease]];

        [tempString release];
        [currentDate setString:@""];


        [comments addObject:comment];
        [comment release];      
    }
}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

    if (([currentElement isEqualToString:@"author"])) { 

        [currentAuthor appendString:[self flattenTEXT:string]];
    } 
    else if (([currentElement isEqualToString:@"content"])) {

        [currentContent appendString:string];
    }

    else if (([currentElement isEqualToString:@"date"])) {

        [currentDate appendString:string];
    }
}


- (NSString *)flattenTEXT:(NSString *)link
{

    //link = [link stringByReplacingOccurrencesOfString:@" " withString:@""];
    link = [link stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    link = [link stringByReplacingOccurrencesOfString:@"\t" withString:@""];
    link = [link stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    return link;
}


- (void)parserDidEndDocument:(NSXMLParser *)parser {


    [currentDate release];
    [currentContent release];
    [currentAuthor release];

    [self.currentElement release];

    [commentController displayData:comments];
}


- (void)dealloc {

    [comments release];
    [months release];
    [super dealloc];

}


/*
 - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
 {
 NSLog(parseError.description);
 }
 */


@end

Would that help ?

gotye
A: 

Is the log always saying that the selector is being sent to an NSString object, or does the object type vary? If it varies, it's usually a sign of a memory management problem.

zenzelezz