Lester
Lester

Reputation: 731

How to set the first date of current week to Wednesday in Swift?

How to set the first date of the week to Wednesday and show the first and last date of week on yellow bar? Because the schedule will update every Wednesday.

App design screenshot

Upvotes: 1

Views: 1033

Answers (1)

Vini App
Vini App

Reputation: 7485

Please check this might help :

var calendar = Calendar.current
calendar.firstWeekday = 4

let startOfWeek = calendar.date(from: calendar.dateComponents([.yearForWeekOfYear, .weekOfYear], from: Date()))!    
let endOfWeek = calendar.date(byAdding: .day, value: 6, to: startOfWeek)!

print(startOfWeek)
print(endOfWeek)

Upvotes: 1

Related Questions