[英]touches.anyObject() no longer working
我有一个我不知道该如何处理的错误。 在
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
//Some code here
let touch = touches.anyObject() as! UITouch
let touchLocation = touch.locationInNode(self)
sceneTouched(touchLocation)
}
我收到错误“集”没有名为“ anyObject”的成员。我一直在互联网上搜索但一无所获。我知道它与Swift中的某些最新更改有关,但我不知道该如何处理它,任何帮助将不胜感激!
尝试这个
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch : UITouch!
touch = touches.first as? UITouch
let touchLocation = touch.locationInNode(self)
sceneTouched(touchLocation)
}
请注意,Swift Set类型没有anyObject方法。 您可以将其强制转换为NSSet,然后使用anyObject方法,也可以仅使用first? 可供Swift中的所有CollectionType使用。
let touch = touches.first as! UITouch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.