UITouch in swift 2

Oka*_*kan 3 ios swift

我正在尝试将我的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)

我该如何解决?

Pau*_*w11 6

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

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