-3

I want to create two variables - one with today's day of the week (Monday - Sunday) and one with the current time. I want to do more than just display it in a label, but am just trying that for now.

I tried this, but my app crashes:

let weekDay = NSCalendar.current.component(.weekday, from: Date())
self.weekDayLabel.text = "\(weekDay)"
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "EEEE"

let dayInWeek = formatter.string(from: date)
Mohd Tahir
  • 36
  • 7
  • Please avoid code only answers. Include some context; an explanation of what you changed or why you wrote it in the way you did or detailing the original cause of the problem so that the OP and others with the same problem can get an understanding of the code you've written and what it changes. – Fabulous Nov 10 '18 at 01:39