Getting time difference in Swift 3
<p>I was trying to get the time difference of two dates from this <a href="http://www.globalnerdy.com/2015/01/29/how-to-work-with-dates-and-times-in-swift-part-two-calculations-with-dates/" rel="nofollow noreferrer">guide</a>. I'm not sure what to put in for the <code>dateComponents</code> argument. When I directly pass in <code>[.hour, .minute]</code>, I get an error: </p>

<pre><code>Playground execution failed: error: MyPlayground.playground:10:46: error: type of expression is ambiguous without more context
let timeDifference = calendar.dateComponents([.hour, .minute], from: stopTime!, to: date!)
                                             ^~~~~~~~~~~~~~~~
</code></pre>

<p>```</p>

<p>I tried to declare it as a constant first but am unsure what the type is. The argument is of type <code>Set&lt;Calendar.Component&gt;</code>, but I'm getting an error when I try to say it's of up <code>Component</code>, <code>DateComponent</code>, or <code>CalendarComponent</code>.</p>

<p>````</p>

<pre><code>let timeFormatter = DateFormatter()
timeFormatter.dateFormat = "hh:mm a "
let time = "12:03 pm"
let stopTime = timeFormatter.date(from: time)

let date = Date()
let calendar = Calendar.current

let components:[DateComponent] = [.hour, .minute]
let timeDifference = calendar.dateComponents(components, from: stopTime!, to: date!)
</code></pre>