救命!我遇到错误’表达式类型'(_,_.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 }
表达式.Now()返回类型dispatchTime,它是一个结构.
let offsetTime = 0将变量初始化为Int.该错误具有误导性,实际上它是一种类型不匹配
虽然编译器可以推断出数字文字的类型
dispatchQueue.main.asyncAfter(deadline: .Now() + 3)
将Int文字或变量添加到dispatchTime值的最可靠方法是具有关联值的dispatchTimeInterval情况.
dispatchQueue.main.asyncAfter(deadline: .Now() + .seconds(offsetTime)
和
dispatchQueue.main.asyncAfter(deadline: .Now() + .seconds(offsetTime) + .seconds(3))
有四个dispatchTimeInterval枚举情况
> .seconds(Int)> .milliseconds(Int)> .microseconds(Int)> .nanoseconds(Int)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。