-1

currentCalendar.dateComponents(components: Set Calendar.Component, from: Date, to: Date)

I want to calculate the number of days between 2 dates, I can't seem to find a tutorial anyway online for swift4 Xcode9 everything else seems to be about the outdated syntax. so I just want to know what should I put in the "components: Set Calendar.Component" part ?

Kenneth Wong
  • 43
  • 2
  • 11
  • 1
    `Set` in your case is simply `[.day]`. The array notation will create the `Set` implicitly. – vadian Nov 19 '17 at 11:11

1 Answers1

0

You should put a Set of the enumeration type Calendar.Component

example:

let s: Set = [Calendar.Component.day]

let c = Calendar(identifier: .gregorian)
let dc = c.dateComponents(s, from: Date.init(timeIntervalSinceNow: -100000), to: Date.init(timeIntervalSinceNow: 0))

let day = dc.day

the day variable is equal to 1

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93