Avatar ·

How to add 1 day to NSDate in Swift? Problem with DateComponents

Hello everyone! I'm a beginner iOS developer writing in Swift. I've encountered what seems like a simple task: I need to take the current date, add exactly 1 day to it, and get a new date. But nothing works! Here's my code: ```swift let currentDate = NSDate() let tomorrow = currentDate.addingTimeInterval(60 * 60 * 24) // 24 hours in seconds print(tomorrow) ``` The problem is that during daylight saving time transitions, 24 hours is not always exactly 1 day. For example, in spring a day can be 23 hours, and in autumn — 25. Because of this, I get the wrong time. Plus, if I want to add 1 month or 1 year, this approach doesn't work at all. I know that in Objective-C, `NSDateComponents` and `NSCalendar` were used for this, but in Swift I'm confused with the new API. I tried writing this: ```swift l