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:
func -(time1: DispatchTime, time2: DispatchTime) -> DispatchTimeInterval {
return DispatchTimeInterval.nanoseconds(Int(time2.uptimeNanoseconds -
time1.uptimeNanoseconds))
}
However, you will need to perform checking for when time2 < time1 and then the
difference doesn’t fit in an Int–these will cause crashes.
Saagar Jha
> On Feb 16, 2017, at 7:56 AM, J.E. Schotsman via swift-users
> <[email protected]> wrote:
>
> Hello,
>
> I am trying to define an operator that subtracts dispatch times:
>
> #import Dispatch
>
> func -( time1: DispatchTime, time2: DispatchTime ) -> DispatchTimeInterval
> {
> return DispatchTimeInterval.nanoseconds( time2.uptimeNanoseconds -
> time1.uptimeNanoseconds )
> }
>
> Compiler says: Ambiguous use of operator ‘-'
> Found this candidate
> Found this candidate
>
> As usual the candidates are unknown.
>
> What am I doing wrong?
>
> Jan E.
> _______________________________________________
> swift-users mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-users
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users