[Solved] How to compare array of dates with greater than current date


i Resolved my issue by using stack overflow suggestions. and i am posting my answer it may helpful for others.

extension Date {
    var startOfWeek: Date? {
        let gregorian = Calendar(identifier: .gregorian)
        guard let sunday = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) else { return nil }
        return gregorian.date(byAdding: .day, value: 1, to: sunday)
    }

    var endOfWeek: Date? {
        let gregorian = Calendar(identifier: .gregorian)
        guard let sunday = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: self)) else { return nil }
        return gregorian.date(byAdding: .day, value: 7, to: sunday)
    }
    func generateDatesArrayBetweenTwoDates(startDate: Date , endDate:Date) ->[Date]
    {
        var datesArray: [Date] =  [Date]()
        var startDate = startDate
        let calendar = Calendar.current
        let fmt = DateFormatter()
        fmt.dateFormat = "dd-MM-YYYY"
        while startDate <= endDate {
            datesArray.append(startDate)
            startDate = calendar.date(byAdding: .day, value: 1, to: startDate)!
        }
        return datesArray
    }
}

i am using that function like this.

func dateList() {
        let startWeek = Date().startOfWeek
        let endWeek = Date().endOfWeek
        datesBetweenArray = Date().generateDatesArrayBetweenTwoDates(startDate: startWeek! , endDate: endWeek!) as NSArray
        print(datesBetweenArray)
}

solved How to compare array of dates with greater than current date