get the date 5 days from now in swift

You can use the Calendar class and the date(byAdding:to:wrappingComponents:) method to get a date that is 5 days from now. Here's an example:

main.swift
let currentDate = Date()
let calendar = Calendar.current
let fiveDaysFromNow = calendar.date(byAdding: .day, value: 5, to: currentDate)
136 chars
4 lines

In this example, we first create a Date object representing the current date. We then create a Calendar object using the current class method. Finally, we use the date(byAdding:to:wrappingComponents:) method to get a new date by adding 5 days to the current date. The value parameter specifies the number of days we want to add, and the .day constant tells the method that we want to add days specifically. The resulting fiveDaysFromNow variable will contain a Date object representing the date that is 5 days from now.

gistlibby LogSnag