Expression type '(_, _.Stride) & # 8594; _ 'is ambiguous with no additional context

Help! I am facing the error "Expression type" (_, _.Stride) โ†’ _ 'ambiguous without extra context ". Does anyone know why this is happening and there is a solution? I am using Swift 4.
Code:

let offsetTime = 0
DispatchQueue.main.asyncAfter(deadline: .now() + offsetTime) { //Expression type '(_, _.Stride) -> _' is ambiguous without more context
    self.currentTaskForUser.text = "Starting\n" + note +  "in"
    self.timerDown(from: 3, to: 1)
}
DispatchQueue.main.asyncAfter(deadline: .now() + offsetTime + 3) { //Expression type '(_, _.Stride) -> _' is ambiguous without more context
    self.currentTaskForUser.text = note
    let difficultyValue = Int(self.difficultyControl.titleForSegment(at: self.difficultyLevel.selectedSegmentIndex)!)!
    self.timerUp(from: 1, to: difficultyValue)
    self.offsetTime += 13
}

      

+3


source to share


1 answer


The expression .now()

returns a type DispatchTime

, which is a structure.

let offsetTime = 0

initializes the variable as Int

. The error is misleading, practically it is a type mismatch


Although the compiler can infer the type of a numeric literal

DispatchQueue.main.asyncAfter(deadline: .now() + 3)

      

The most reliable way to add a literal or variable Int

to a value DispatchTime

is DispatchTimeInterval

with an associated value event .



DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(offsetTime)

      

and

DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(offsetTime) + .seconds(3))

      

There are four enumeration cases DispatchTimeInterval

  • .seconds(Int)

  • .milliseconds(Int)

  • .microseconds(Int)

  • .nanoseconds(Int)

+10


source







All Articles