gpt4 book ai didi

ios - 快速 2 中的 UITouch

转载 作者:搜寻专家 更新时间:2023-10-31 22:07:27 26 4
gpt4 key购买 nike

我正在尝试将我的 swift 1.2 代码转换为 2.0 我有一个这样的函数:

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let anyTouch = (touches.first as? UITouch)!
}

但我收到以下错误:

Downcast from 'UITouch?' to 'UITouch' only unwraps optionals; did you mean to use '!'?

我该如何解决?

最佳答案

Set 内容的类型在函数签名中指定为 UITouch,因此您不需要向下转换。您只需要打开可选的包装即可。

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let anyTouch = touches.first
}

关于ios - 快速 2 中的 UITouch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32770825/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com