I am trying to calculate the difference between 2 dates (one is the current date and the other from datepicker) in weeks and days then displaying the result on a label, that
You are close. Just add .weekOfMonth
(meaning "quantity of weeks"
according to the API documentation) to the allowed units.
Example:
let now = Date()
let endDate = now.addingTimeInterval(24 * 3600 * 17)
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.day, .weekOfMonth]
formatter.unitsStyle = .full
let string = formatter.string(from: now, to: endDate)!
print(string) // 2 weeks, 3 days
Setting maximumUnitCount = 2
is not necessary because there are
only two allowed units.