How to get the current time of SWIFT?

I want to get the current time, so far I have completed this:

let date = NSDate() 
let calender = NSCalendar.currentCalendar()
let components = calender.component([.Hour, .Minute], fromDate: date)

Then I try to get the hour of the component< /p>

let hour = components.hour

This gave me “value of type” Int “no member’hour'”. Any suggestions?

change

let components = calender.component([.Hour, .Minute], fromDate: date)

to

let components = calender.components([.Hour, .Minute], fromDate: date)

I want to get the current time, so far I have completed this:

< /p>

let date = NSDate()
let calender = NSCalendar.currentCalendar()
let components = calender.component([.Hour, .Minute], fromDate: date)

Then I try to get the hour of the component

let hour = components.hour

This gives me the “value of type “Int” no Member’hours'”. Any suggestions?

Change

let components = calender.component([.Hour, .Minute] , fromDate: date)

to

let components = calender.components([.Hour, .Minute], fromDate: date)

Leave a Comment

Your email address will not be published.