ios - NSDateComponents to NSDate - Swift -


i have function :

private func getcurrentdatecomponent() -> nsdatecomponents {         let date = nsdate()         let calendar = nscalendar.currentcalendar()         let components = calendar.components(.calendarunithour | .calendarunitminute | .calendarunitmonth | .calendarunityear | .calendarunitday, fromdate: date)         return components     } 

when call , use function date

var d = this.getcurrentdatecomponent().date 

i don't know why variable d nil...

thank help

ysee

that's how it:

let allunits = nscalendarunit(rawvalue: uint.max) return uicalendar.currentcalendar().components(allunits, fromdate: nsdate()) 

note in swift 2.0 bitwise or operator | not used more, instead nscalendarunit conforms optionsettype format:

let timeunits : nscalendarunit = [.hour, .minute, .second] 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -