我试图编写一个方法来运行for循环检查日期是否在今天之前,如果是,则需要增加一个NSDateComponent
检查日期是否在今天之前的方法:
- (BOOL) isDatePassedToday:(NSDate *)recurringDate
{
if ([recurringDate compare:[NSDate date]] == NSOrderedDescending)
return NO;
return YES;
}
我需要for循环工作的逻辑:
-(NSDate *)calculateRecurringReminder:(NSDate *)startDate using:(NSDateComponents*)doItAgainComponents
{
NSDate *recurringDate = [[NSDate alloc]init];
recurringDate = [[NSCalendar currentCalendar] dateByAddingComponents:doItAgainComponents toDate:recurringDate options:0];
// The loop to add components
for ([self isDatePassedToday:recurringDate]; [self isDatePassedToday:recurringDate] == YES; doItAgainComponents)
{
recurringDate = [[NSCalendar currentCalendar] dateByAddingComponents:doItAgainComponents toDate:recurringDate options:0];
}
return recurringDate;
}
答案 0 :(得分:0)
也许你的意思是:
-(NSDate *)calculateRecurringReminder:(NSDate *)startDate using:(NSDateComponents*)doItAgainComponents {
NSDate *recurringDate = startDate;
while (![self isDatePassedToday:recurringDate]) {
recurringDate = [[NSCalendar currentCalendar] dateByAddingComponents:doItAgainComponents toDate:recurringDate options:0];
}
return recurringDate;
}