Okay so i got this clas called event.
It has a property called eventDate wich is a NSDate. I made a method to return how many years it is since the event date:
- (double)yearsSinceEvent {
double years;
// Get the system calendar
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
// Create the NSDates
NSDate *date1 = self.eventDate;
NSDate *date2 = [NSDate date];
// Get conversion to months, days, hours, minutes
unsigned int unitFlags = NSYearCalendarUnit;
NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:date1 toDate:date2 options:0];
years = [conversionInfo year];
[date1 release];
[date2 release];
return years;
}
when configuring my tableview cells i do:
cell.textLabel.text = [[events objectAtIndex:indexPath.row] name];
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d year's ago", [events objectAtIndex:indexPath.row] yearsSinceEvent]];
But this throws this error:
* __NSAutoreleaseFreedObject(): release of previously deallocated object (0x595bda0) ignored
What am i doing wrong here?
If i dont release date1 and date2 i dont get the error, but the method returns 0..
If i do the yearsSinceEvent code in the cell configuration method instead, and dont release date 1 and date 2 it works..
How should i do this?