2011-11-02 2 views
1

디버깅 흔적이 거의없이 내 앱에서 하드 크래시가 발생하는 코드 변경 사항으로 인해 버그를 파악할 수 없습니다.NSTimeInterval을 사용하여 설명 할 수없는 크래시

여기에 원래의 방법

+ (NSArray *)currentReservations { 
    NSTimeInterval interval = [[NSDate date] timeIntervalSince1970]; 
    double futureTimeframe = interval + SecondsIn24Hours; 
    NSArray *reservations = [Reservation findWithSql:@"select * from Reservation where timestamp < ? and timestamp > ?" withParameters:[NSArray arrayWithObjects:[NSNumber numberWithDouble:ceil(futureTimeframe)], [NSNumber numberWithDouble:floor(interval)], nil]]; 
    return reservations; 
} 

나는 현재와 미래의 시작 24시 사이에 타임 스탬프가 모든 레코드를 찾기 위해 데이터베이스를 조회 할 수 있도록하는 방법은 몇 가지 변수를 설정합니다. 지금과 내일 (다음 날 자정) 사이에 타임 스탬프를 가진 모든 레코드를 쿼리하는 방법을 변경해야합니다, 그래서 나는 그러나

this other stackoverflow question

+ (NSArray *)currentReservations { 
    NSDate *today = [NSDate date]; 
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
    NSDateComponents *components = [[NSDateComponents alloc] init]; 
    [components setDay:1]; // tomorrow 
    NSDate *tomorrow = [gregorian dateByAddingComponents:components toDate:today options:0]; 
// [components release]; // dont think we need this release, but it is in the example here: https://stackoverflow.com/questions/181459/is-there-a-better-way-to-find-midnight-tomorrow 
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; 
    components = [gregorian components:unitFlags fromDate:tomorrow]; 
    [components setHour:0]; 
    [components setMinute:0]; 
    NSDate *tomorrowMidnight = [gregorian dateFromComponents:components]; 
    [components release], components=nil; 
    [gregorian release], gregorian=nil; 


    NSTimeInterval interval = [today timeIntervalSince1970]; 
    NSTimeInterval tomorrowInterval = [tomorrowMidnight timeIntervalSince1970]; 

    NSArray *reservations = [Reservation findWithSql:@"select * from Reservation where timestamp < ? and timestamp > ?" withParameters:[NSArray arrayWithObjects:[NSNumber numberWithDouble:tomorrowInterval], [NSNumber numberWithDouble:floor(interval)], nil]]; 
    return reservations; 
} 
에 기반이에 코드를 업데이트 할 때이 두 라인 :

NSTimeInterval interval = [today timeIntervalSince1970]; 
    NSTimeInterval tomorrowInterval = [tomorrowMidnight timeIntervalSince1970]; 

이 포함되면 앱이 다운됩니다. 나는이 두 줄로 줄 지어 설명했다.

나는 무엇이 잘못되었는지에 대해 완전히 망한다.

+0

"앱이 다운되는 경우"라는 의미는 무엇입니까? 어떤 방법으로? 스택 트레이스는 무엇입니까? – Jim

+0

시뮬레이터에서 주 루프로 하드 충돌이 발생하면 – cpjolicoeur

+1

역 추적 (디버그 콘솔에서 bt를 입력)해야합니다. "충돌"이 문제를 해결하는 데 도움이되지 않습니다. – jrturton

답변

1

충돌 스택 추적이 _CFAutoreleasePoolPop 내부의 objc_msgSend에 있기 때문에 아마도 over-release 버그 일 가능성이 있습니다.

이 줄은 잘못된 것입니다 : 당신이 구성 요소를 보유하고 있지 않습니다

[components release], components=nil; 

. 그것을 준 방법의 이름을보십시오. 너는 그것을 과도하게 발표하고있다.

0

rob mayoff가 말했듯이 두 번째 릴리스는 잘못되었습니다 (첫 번째는 필요합니다). 대신 다음을 시도해보십시오.

+ (NSArray *)currentReservations { 
    NSDate *today = [NSDate date]; 
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
    NSDateComponents *components = [[[NSDateComponents alloc] init] autorelease]; 
    [components setDay:1]; // tomorrow 
    NSDate *tomorrow = [gregorian dateByAddingComponents:components toDate:today options:0]; 
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; 
    components = [gregorian components:unitFlags fromDate:tomorrow]; 
    [components setHour:0]; 
    [components setMinute:0]; 
    NSDate *tomorrowMidnight = [gregorian dateFromComponents:components]; 
    [gregorian release], gregorian=nil; 


    NSTimeInterval interval = [today timeIntervalSince1970]; 
    NSTimeInterval tomorrowInterval = [tomorrowMidnight timeIntervalSince1970]; 

    NSArray *reservations = [Reservation findWithSql:@"select * from Reservation where timestamp < ? and timestamp > ?" withParameters:[NSArray arrayWithObjects:[NSNumber numberWithDouble:tomorrowInterval], [NSNumber numberWithDouble:floor(interval)], nil]]; 
    return reservations; 
} 
관련 문제