Create NSDate from day/month/year

 Problem

I want to create an NSDate object using the values for day, month and year.



 Recipe


// Initialize Date components
var c = NSDateComponents()
c.year = 2015
c.month = 8
c.day = 31

// Get NSDate given the above date components
var date = NSCalendar(identifier: NSCalendarIdentifierGregorian)?.dateFromComponents(c)

print(date!)
				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground