Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[NSDateFormatter class]: message sent to deallocated instance

what is the problem in code below?

NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterMediumStyle];
error.timestamp =  [formatter stringFromDate:date];
[formatter release];

I am getting this error below:

 *** -[NSDateFormatter class]: message sent to deallocated instance 0x8c04f00

How can I resolve it?

I don't use ARC.

like image 386
cateof Avatar asked Aug 07 '26 09:08

cateof


1 Answers

The code you posted seems to be correct.
Are you sure you are getting the message from the code you posted?
Can you set an exception breakpoint in Xcode to check if the above code is the problem?

If you are not re-using NSDateFormatter, you could use the following class method to get a date string in one line of code:

[NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterMediumStyle]
like image 186
Thomas Zoechling Avatar answered Aug 10 '26 00:08

Thomas Zoechling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!