NSPredicate- For finding events that occur between a certain date range

前端 未结 4 1715
情深已故
情深已故 2021-01-03 10:42

This is a little more complicated then just

NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"startDate >= %@ AND endDate <= %@\", startDay,         


        
4条回答
  •  被撕碎了的回忆
    2021-01-03 11:20

    What you want is:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate <= %@ AND endDate >= %@", endDay, startDay];
    

    In other words, you're eliminating events that start after the end of the range or end before the start, i.e., events that have an empty intersection with the range.

提交回复
热议问题