---
title: "nextDate(after:matching:matchingPolicy:repeatedTimePolicy:direction:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/calendar/nextdate(after:matching:matchingpolicy:repeatedtimepolicy:direction:)"
---

# nextDate(after:matching:matchingPolicy:repeatedTimePolicy:direction:)

Computes the next date which matches (or most closely matches) a given set of components.

## Declaration

```swift
func nextDate(after date: Date, matching components: DateComponents, matchingPolicy: Calendar.MatchingPolicy, repeatedTimePolicy: Calendar.RepeatedTimePolicy = .first, direction: Calendar.SearchDirection = .forward) -> Date?
```

## Parameters

- `date`: The starting date.
- `components`: The components to search for.
- `matchingPolicy`: Specifies the technique the search algorithm uses to find results. Default value is .nextTime.
- `repeatedTimePolicy`: Specifies the behavior when multiple matches are found. Default value is .first.
- `direction`: Specifies the direction in time to search. Default is .forward.

## Return Value

Return Value A Date representing the result of the search, or nil if a result could not be found.

## Discussion

Discussion The general semantics follow those of the enumerateDates function. To compute a sequence of results, use the enumerateDates function, rather than looping and calling this method with the previous loop iteration’s result.

## See Also

### Scanning Dates

- [startOfDay(for:)](foundation/calendar/startofday(for:).md)
- [enumerateDates(startingAfter:matching:matchingPolicy:repeatedTimePolicy:direction:using:)](foundation/calendar/enumeratedates(startingafter:matching:matchingpolicy:repeatedtimepolicy:direction:using:).md)
- [Calendar.MatchingPolicy](foundation/calendar/matchingpolicy.md)
- [Calendar.RepeatedTimePolicy](foundation/calendar/repeatedtimepolicy.md)
