I am having a mutable array in that array i am having only past date, current date & future date. I have to separate the future date & store into another array. Can you help me.
This is my array:
uniqueItems(
"2015-03-01",
"2015-02-28",
"2015-02-22",
"2015-02-21",
"2015-02-20",
"2015-02-15",
"2015-02-14",
"2015-02-13",
"2015-02-08",
"2015-02-07",
"2015-02-01",
"2015-01-31",
"2015-01-30",
"2015-01-25",
"2015-01-24",
"2015-01-18",
"2015-01-17",
"2015-01-16",
"2015-01-11",
"2015-01-10",
"2014-12-07"
I have tried this coding, but is not working.
NSDate *currentDate = [NSDate date];
NSDate* dateAdded=(NSDate*)[uniqueItems objectAtIndex:0];
double min = [currentDate timeIntervalSinceDate:dateAdded];
int minIndex = 0;
for (int i = 1; i < [uniqueItems count]; ++i)
{
double currentmin = [currentDate timeIntervalSinceDate:[uniqueItems objectAtIndex:i]];
if (currentmin < min) {
min = currentmin;
minIndex = i;}}
Your array is of string format not an NSDate object. You can convert a string to nsdate
and then you could do your check.
This is a idea. Sorry, I'm coding in notepad without test.
you can use
NSPredicate
block for that. your array does not containNSDate
objects so we need to convert it intoNSDate
and then compare with[NSDate date]
if you pass
NSOrderedAscending
will give you future dates if you passNSOrderedDescending
will give you past dates.