Instance Method
date(byAdding:value:to:wrappingComponents:)
iOS 8.0+
iPadOS 8.0+
Mac Catalyst 8.0+
macOS 10.10+
tvOS 9.0+
watchOS 2.0+
Returns a new Date representing the date calculated by adding an amount of a specific component to a given date.
func date(byAdding component: Calendar.Component, value: Int, to date: Date, wrappingComponents: Bool = false) -> Date?
Parameters
componentA single component to add.
valueThe value of the specified component to add.
dateThe starting date.
wrappingComponentsIf
true, the component should be incremented and wrap around to zero/one on overflow, and should not cause higher components to be incremented. The default value isfalse.
Return Value
A new date, or nil if a date could not be calculated with the given input.