我正在尝试将我的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 '!'?
我该怎么修复它?
let anyTouch = touches.first
- Paulw11let anyTouch = touches.first!
,您仍然需要解包可选项,但是您不需要向下转换,因为该类型已被指定为 UITouch。 - Paulw11