Friday, November 28, 2014

Extending NSDate to add a Start of Day Method

New NSDate objects are created by default with the current time and date. This is useful for most things. However sometimes you may only want the date. One way to achieve this is to modify the NSDate object's time elements using  the NSCalendar and NSDateComponent classes to set the time to the first second of the day. This article will describe how to do this by creating a Swift extension to the NSDate class that will add a 'start of day' method.