Reputation: 39
Time profiler say that my code to expressive in memory and I see lags while scrolling tableView.
How can I replace this code?
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm:ss"];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_duration doubleValue]];
return [dateFormatter stringFromDate:date];
_duration have value 123
I need string from _duration like 2:03 sec
Upvotes: 2
Views: 1186
Reputation: 318854
Two options:
1) Create the date formatter once and reuse it.
2) Don't use a date formatter. There's no need. It's trivial to convert your duration to minutes and seconds.
int duration = [_duration intValue];
int mins = duration / 60;
int secs = duration % 60;
return [NSString stringWithFormat:@"%02d:%02d", mins, secs];
Upvotes: 4