Fetching Dates Which Comes Between StartDate and E

2020-03-27 10:27发布

I am having array of dates and i need to fetch only those dates which comes between two differnt dates (StartDate and EndDate)..

can any one help me out in solving this... thanks in advance

2条回答
走好不送
2楼-- · 2020-03-27 11:05

Assuming you have startDate and endDate instances of type NSDate you can:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SELF > %@) AND (SELF < %@)", startDate, endDate];
NSArray *result = [arrayWithDates filteredArrayUsingPredicate:predicate];
查看更多
3楼-- · 2020-03-27 11:08

Check out filterWithPredicate, it allows you to create a filter rule to apply against all elements in the array.

查看更多
登录 后发表回答