swift – 表达式类型'(_,_ .tride) – > _’是不明确的,
发布时间:2020-12-14 02:28:17 所属栏目:百科 来源:网络整理
导读:救命!我遇到错误’表达式类型'(_,_.Stride) – 如果没有更多的上下文,_’是模棱两可的.有谁知道为什么会这样,并有解决方案吗?我正在使用 Swift 4. 码: let offsetTime = 0DispatchQueue.main.asyncAfter(deadline: .now() + offsetTime) { //Expression t
救命!我遇到错误’表达式类型'(_,_.Stride) – >如果没有更多的上下文,_’是模棱两可的.有谁知道为什么会这样,并有解决方案吗?我正在使用
Swift 4.
码: let offsetTime = 0 DispatchQueue.main.asyncAfter(deadline: .now() + offsetTime) { //Expression type '(_,_.Stride) -> _' is ambiguous without more context self.currentTaskForUser.text = "Startingn" + 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) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |