Pregunta

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?

¿Fue útil?

Solución

You're calling -appendString: with myDate, which isn't a string. It's an NSDate. 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 using NSDateFormatter, 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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top