Instance Method


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


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



The starting date.


The components to search for.


Specifies the technique the search algorithm uses to find results. Default value is .nextTime.


Specifies the behavior when multiple matches are found. Default value is .first.


Specifies the direction in time to search. Default is .forward.

Return Value

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


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

func startOfDay(for: Date) -> Date

Returns the first moment of a given Date, as a Date.

func enumerateDates(startingAfter: Date, matching: DateComponents, matchingPolicy: Calendar.MatchingPolicy, repeatedTimePolicy: Calendar.RepeatedTimePolicy, direction: Calendar.SearchDirection, using: (Date?, Bool, inout Bool) -> Void)

Computes the dates which match (or most closely match) a given set of components, and calls the closure once for each of them, until the enumeration is stopped.

enum Calendar.MatchingPolicy

A hint to the search algorithm to control the method used for searching for dates.

enum Calendar.RepeatedTimePolicy

Determines which result to use when a time is repeated on a day in a calendar (for example, during a daylight saving transition when the times between 2:00am and 3:00am may happen twice).