Instance Method
nextDate(after:matching:matchingPolicy:repeatedTimePolicy:direction:)
iOS 8.0+
iPadOS 8.0+
Mac Catalyst 8.0+
macOS 10.10+
tvOS 9.0+
watchOS 2.0+
Computes the next date which matches (or most closely match) 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?
Parameters
dateThe starting date.
componentsThe components to search for.
matchingPolicySpecifies the technique the search algorithm uses to find results. Default value is
.nextTime.repeatedTimePolicySpecifies the behavior when multiple matches are found. Default value is
.first.directionSpecifies 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.
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.