Ios 如何通过触摸检测对象索引?

Ios 如何通过触摸检测对象索引?,ios,swift,touch,Ios,Swift,Touch,我正在开发一个益智游戏,我想检测触摸发生的图像索引,我在objective-C教程中这样做,它说: -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch* mytouch = [[ touches allObjects] objectAtIndex : 0 ]; } 所以他是这样做的,但是用斯威夫特,我怎么写呢 请帮我解决这个问题 如果有人想了解更多信息,请参阅本教程 在22

我正在开发一个益智游戏,我想检测触摸发生的图像索引,我在objective-C教程中这样做,它说:

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
       UITouch* mytouch = [[ touches allObjects] objectAtIndex : 0 ];
       }
所以他是这样做的,但是用斯威夫特,我怎么写呢

请帮我解决这个问题

如果有人想了解更多信息,请参阅本教程


在22:00直走,你会发现这个。

这是同样的swift代码。请注意,
touchs
数组可以为空,并且
first
属性返回可选值。这就是我使用可选竞价的原因

override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    let touches = touches.allObjects as [UITouch]

    if let myTouch = touches.first {

    }
}