对于NSDate的循环

时间:2012-03-27 02:44:21

标签: ios4 for-loop nsdate ios5

我正在尝试使用NSDates创建一个for循环,以便循环在for循环的每个循环中增加1天...

NSDate *startDate = datePicker.date;
NSDate *endDate = datePicker2.date;

for (int i = startDate; i < endDate; i++) 
{

}

构建失败是因为我干扰了NSDate,其中int是...... 我也试过......

NSDate *startDate = datePicker.date;
NSDate *endDate = datePicker2.date;

for (NSDate *i = startDate; i < endDate; i++) 
{

}

那也没有。非常感谢任何帮助,提前谢谢。

1 个答案:

答案 0 :(得分:3)

for (NSDate *date = [startDate copy]; [date compare: endDate] < 0; date = [date dateByAddingTimeInterval:24 * 60 * 60] ) 
    {
        NSLog( @"%@ in [%@,%@]", date, startDate, endDate );
    }

Using NSDate in While loop