0

现在有了 swift 2.0,IOS 8.3 这个代码不再工作了。“Set”没有名为“allObjects”的成员

public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

    var touch: UITouch = event.allTouches()?.allObjects.last as UITouch!
}

我尝试了很多东西,但似乎没有任何效果,知道吗?

谢谢

4

2 回答 2

3

Swift 1.2 引入了原生Set类型,但不像NSSet它没有anyObject方法。你有几个选择。您可以使用该first()方法,也可以利用将 Swift Set 桥接到 NSSet 的能力 -

let touch = touches.first() as? UITouch

或者

let touchesSet=touches as NSSet
let touch=touchesSet.anyObject() as? UITouch
于 2015-04-12T02:47:32.603 回答
0

我也注意到了这一点。我不确定这是否是这些天原始代码的实际更改...我确定不是。但我只是将该代码更改为:

(touches: NSObject, withEvent event: UIEvent)

抱歉,如果这对您不起作用。它对我来说非常好。

于 2015-04-12T01:29:37.260 回答