You can use the Calendar and DateComponents classes in Swift to get the date 5 weeks from now. Here's an example code snippet that demonstrates how to do that:
main.swift407 chars16 linesIn this code, we first get the current date using the Date() initializer. We then create a Calendar object using the Calendar.current property. Next, we create a DateComponents object and set the weekOfYear property to 5 to indicate that we want to add 5 weeks to the current date.
Finally, we use the date(byAdding:to:) method of the calendar object to add the date components to the current date and get the future date. We then print the future date using the print() function. Note that the ! force-unwraps the optional future date to ensure that it is not nil.
gistlibby LogSnag