OscarTheGrouch
OscarTheGrouch

Reputation: 2384

For Loop for NSDate

I'm trying to create a for loop with NSDates, so that the loop would increment by 1 day each cycle of the for loop...

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

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

}

The build fails because of me jamming a NSDate where the int is... I also tried...

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

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

}

That did not build either. Any help would be greatly appreciated, thanks in advance.

Upvotes: 2

Views: 600

Answers (1)

OscarTheGrouch
OscarTheGrouch

Reputation: 2384

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

Upvotes: 3

Related Questions