<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">DispatchTimeInterval.nanoseconds expects an Int, while uptimeNanoseconds is an UInt64 (an thus so is their difference). You can “fix” this by adding an explicit cast:<div class=""><br class=""></div><div class="">func -(time1: DispatchTime, time2: DispatchTime) -&gt; DispatchTimeInterval {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return DispatchTimeInterval.nanoseconds(Int(time2.uptimeNanoseconds - time1.uptimeNanoseconds))</div><div class="">}</div><div class=""><br class=""></div><div class="">However, you will need to perform checking for when time2 &lt; time1 and then the difference doesn’t fit in an Int–these will cause crashes.</div><div class=""><br class=""><div class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha</div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Feb 16, 2017, at 7:56 AM, J.E. Schotsman via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello,<br class=""><br class="">I am trying to define an operator that subtracts dispatch times:<br class=""><br class="">#import Dispatch<br class=""><br class="">func -( time1: DispatchTime, time2: DispatchTime ) -&gt; DispatchTimeInterval<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>{<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return DispatchTimeInterval.nanoseconds( time2.uptimeNanoseconds - time1.uptimeNanoseconds )<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}<br class=""><br class="">Compiler says: Ambiguous use of operator ‘-'<br class="">Found this candidate<br class="">Found this candidate<br class=""><br class="">As usual the candidates are unknown.<br class=""><br class="">What am I doing wrong?<br class=""><br class="">Jan E.<br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>