by default different Calendar.Identifier values have different Calendar.current.firstWeekday.
Also there is a possibility to choose any day as start of week in Settings.
Suggesting to change this code
var weekday: Int { return dateComponents.weekday! }
by adding dependency on Calendar.current.firstWeekday
var weekday: Int { return (dateComponents.weekday! - Calendar.current.firstWeekday + 7) % 7 + 1 }
by default different Calendar.Identifier values have different Calendar.current.firstWeekday. Also there is a possibility to choose any day as start of week in Settings.
Suggesting to change this code
var weekday: Int { return dateComponents.weekday! }
by adding dependency on Calendar.current.firstWeekday
var weekday: Int { return (dateComponents.weekday! - Calendar.current.firstWeekday + 7) % 7 + 1 }