I have been bothered by this problem for a long time.
I have a NSString which is the received from a RSS parser, I can successfully NSlog it on the screen, but when I try to append it to an existing NSmutablearray, it causes exception.
Here is my code.
//mystring is a NSMutableString with some content initialized succesfully
NSString *myDate = [dic objectForKey:@"date"];
NSLog(@"%@ and %@",myString,myDate);
[myString appendString:myDate];
until the NSLog, both myDate and myString are printed on screen correctly as I desire, but the appendString line causes error
[_NSDate length]: unrecognized selector sent to instance 0*7141a00
Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reasons: ‘-[__NSDate length]: ……….
Could someone please help me?
You’re calling
-appendString:withmyDate, which isn’t a string. It’s anNSDate. You can’t pass it to an API that expects a string. You need to convert it into a string somehow. This is probably best done usingNSDateFormatter, which gives you full control over how to format your date as a string.For testing purposes though, you can just replace your last line with
[myString appendString:[myDate description]]and it should stop crashing.