デバッグの痕跡がほとんどないと、アプリでハード クラッシュを引き起こしているコード変更のバグを特定できないようです。
元の方法はこちら
+ (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 時間先までのタイムスタンプを持つすべてのレコードを見つけることができます。現在と明日の間 (翌日の午前 0 時) のタイムスタンプを持つすべてのレコードをクエリするようにメソッドを変更する必要があるため、この他のスタックオーバーフローの質問に基づいてコードを更新しました
+ (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;
}
ただし、次の 2 行の場合:
NSTimeInterval interval = [today timeIntervalSince1970];
NSTimeInterval tomorrowInterval = [tomorrowMidnight timeIntervalSince1970];
アプリのクラッシュが含まれています。コメントアウトするなどして、この2行に絞り込みました。
私は何が悪いのか完全に途方に暮れています。