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
Post a Comment