How do I create an NSDate object with a custom date other than the current date? For example I would like to create a var of yesterday or of 2 days ago.
The Rob's answer works great. If you are heavily using that kind of calculations you can even encapsulate that logic and make your own custom extensions and wrappers.
That said i will suggest to take a look too at this fantastic library called SwiftDate. Even if you aren't using it, the README worth reading.
It introduces the definition or Region that can be super useful for some scenarios and some handy initializers.
Some cool stuffs and samples:
(1.years - 2.hours + 16.minutes).fromNow()let dateInUTC = (2015.years | 12.months | 25.days | 20.hours | 10.minutes).inUTCRegionlet date = 5.days.fromNow, let date = 4.hours.agolet date = (6.hours + 2.minutes).fromNow(region: inRome)Hope it helps.