У меня есть метод, который запускает невероятно медленное тестирование в устройстве (iPhone3G) по сравнению с симулятором.
Хотя симулятор может обрабатывать около 100 выполнений метода за 1 секунду, устройство может запускаться только 4 раза, считая метод за секунду.
Что может сделать это бездельником?
КОД:
Примечание. Метод вычисляет удобную для человека строку по двум датам (дата начала и дата окончания события).
-(void)calculateDiaDeInicioYFinTexto
{
NSLog(@"inicio");
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
NSMutableString *auxString = [NSMutableString string];
NSLocale *currLocale = [NSLocale currentLocale];
NSString *stringFormatDay = [NSDateFormatter dateFormatFromTemplate:@"d"
options:0
locale:currLocale];
NSString *stringFormatDayMonth = [NSDateFormatter dateFormatFromTemplate:@"dMMMM"
options:0
locale:currLocale];
NSString *stringFormatDayMonthYear = [NSDateFormatter dateFormatFromTemplate:@"dMMMMYYYY"
options:0
locale:currLocale];
NSDateFormatter *formatterDay = [[NSDateFormatter alloc] init];
[formatterDay setDateFormat:stringFormatDay];
[formatterDay setLocale:currLocale];
NSDateFormatter *formatterDayMonth = [[NSDateFormatter alloc] init];
[formatterDayMonth setDateFormat:stringFormatDayMonth];
[formatterDayMonth setLocale:currLocale];
NSDateFormatter *formatterDayMonthYear = [[NSDateFormatter alloc] init];
[formatterDayMonthYear setDateFormat:stringFormatDayMonthYear];
[formatterDayMonthYear setLocale:currLocale];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *dateComponentsNow = [calendar components:(NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit)
fromDate:[NSDate date]];
NSDateComponents *dateComponentsInicio = [calendar components:(NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit)
fromDate:self.diaDeInicio];
NSDate *diaDeInicioTimeless = [calendar dateFromComponents:dateComponentsInicio];
NSDateComponents *dateComponentsFin = [calendar components:(NSYearCalendarUnit |
NSMonthCalendarUnit |
NSDayCalendarUnit)
fromDate:self.diaDeFin];
NSDate *diaDeFinTimeless = [calendar dateFromComponents:dateComponentsFin];
if ( [diaDeInicioTimeless isEqualToDate:diaDeFinTimeless] ) {
// dates are the same
if ( dateComponentsInicio.year == dateComponentsNow.year ) {
// date is in the current year
[auxString appendFormat:@"%@", [formatterDayMonth stringFromDate:self.diaDeInicio]];
} else {
// date is in another year
[auxString appendFormat:@"%@", [formatterDayMonthYear stringFromDate:self.diaDeInicio]];
}
} else {
// dates are different
if ( dateComponentsInicio.year == dateComponentsFin.year ) {
// years are the same
if ( dateComponentsInicio.month == dateComponentsFin.month ) {
// Months are the same
if ( dateComponentsInicio.year == dateComponentsNow.year ) {
// date is in the current year
[auxString appendFormat:@"%@ - %@",
[formatterDay stringFromDate:self.diaDeInicio],
[formatterDayMonth stringFromDate:self.diaDeFin]];
} else {
// date is in another year
[auxString appendFormat:@"%@ - %@",
[formatterDay stringFromDate:self.diaDeInicio],
[formatterDayMonthYear stringFromDate:self.diaDeFin]];
}
} else {
// Months are different
if ( dateComponentsInicio.year == dateComponentsNow.year ) {
// date is in the current year
[auxString appendFormat:@"%@ - %@",
[formatterDayMonth stringFromDate:self.diaDeInicio],
[formatterDayMonth stringFromDate:self.diaDeFin]];
} else {
// date is in another year
[auxString appendFormat:@"%@ - %@",
[formatterDayMonth stringFromDate:self.diaDeInicio],
[formatterDayMonthYear stringFromDate:self.diaDeFin]];
}
}
} else {
// Years are different
[auxString appendFormat:@"%@ - %@",
[formatterDayMonthYear stringFromDate:self.diaDeInicio],
[formatterDayMonthYear stringFromDate:self.diaDeFin]];
}
}
self.diaDeInicioYFinTexto = auxString;
[formatterDay release];
[formatterDayMonth release];
[formatterDayMonthYear release];
[localPool release];
NSLog(@"Fin");
}