救命!我遇到错误'表达式类型'(_,_.Stride) - > _'是不明确的,没有更多的上下文'.有谁知道为什么会这样,并有解决方案吗?我使用的是Swift 4.
代码:
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
}
Run Code Online (Sandbox Code Playgroud)
vad*_*ian 13
表达式.now()返回DispatchTime一个结构类型.
let offsetTime = 0将变量初始化为Int.该错误具有误导性,实际上它是一种类型不匹配
虽然编译器可以推断出数字文字的类型
DispatchQueue.main.asyncAfter(deadline: .now() + 3)
Run Code Online (Sandbox Code Playgroud)
向Int文本或变量添加DispatchTime值的最可靠方法是DispatchTimeInterval具有关联值的情况.
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(offsetTime)
Run Code Online (Sandbox Code Playgroud)
和
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(offsetTime) + .seconds(3))
Run Code Online (Sandbox Code Playgroud)
有四个DispatchTimeInterval枚举案例
.seconds(Int).milliseconds(Int).microseconds(Int).nanoseconds(Int)| 归档时间: |
|
| 查看次数: |
1919 次 |
| 最近记录: |