我正在尝试将我的swift 1.2代码转换为2.0我有这样的函数:
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let anyTouch = (touches.first as? UITouch)!
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Downcast from 'UITouch?' to 'UITouch' only unwraps optionals; did you mean to use '!'?
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
Set的内容类型被指定为UITouch在函数签名中,因此您不需要向下转换.您只需要打开可选项.
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let anyTouch = touches.first
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2248 次 |
| 最近记录: |