Your error message is due to the fact that in the line
if let todayDate = NSDate()
if let ...is of particular importance in fast. The compiler is trying to bind an optional variable to a constant. Since it NSDate()does not return an optional value, this is an error.
Leave the value ifand it should work:
func getDayOfWeek()->Int? {
let todayDate = NSDate()
let myCalendar = NSCalendar(calendarIdentifier: NSGregorianCalendar)
let myComponents = myCalendar?.components(.WeekdayCalendarUnit, fromDate: todayDate)
let weekDay = myComponents?.weekday
return weekDay
}
source
share