Swift 3 - Comparing Date objects

后端 未结 14 1505
野的像风
野的像风 2020-11-30 07:14

I\'m updating my app to Swift 3.0 syntax (I know it\'s still in beta but I want to be prepared as soon as it released).

Until the previous Beta of Xcode (Beta 5) I wa

14条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 07:41

    extension Date {
     func isBetween(_ date1: Date, and date2: Date) -> Bool {
        return (min(date1, date2) ... max(date1, date2)).contains(self)
      }
    }
    
    let resultArray = dateArray.filter { $0.dateObj!.isBetween(startDate, and: endDate) }
    

提交回复
热议问题