Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift .anyObject()不再工作_Swift_Sprite Kit - Fatal编程技术网

Swift .anyObject()不再工作

Swift .anyObject()不再工作,swift,sprite-kit,Swift,Sprite Kit,我有一个错误,我不知道如何处理。在 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { //Some code here let touch = touches.anyObject() as! UITouch let touchLocation = touch.locationInNode(self) scene

我有一个错误,我不知道如何处理。在

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)

}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
//这里有一些代码
让touch=touch.anyObject()作为!UITouch
让touchLocation=touch.locationInNode(自身)
场景触摸(触摸位置)
}
我发现错误“Set”没有名为“anyObject”的成员。我在internet上搜索了所有内容,但没有找到任何内容。我知道这与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)
 }
override func touchsbegined(touchs:Set,withEvent-event:UIEvent){
var touch:UITouch!
触摸=触摸。首先作为?UITouch
让touchLocation=touch.locationInNode(自身)
场景触摸(触摸位置)
}

请注意,Swift集合类型没有任何对象方法。您可以将其强制转换为NSSet,然后使用任何对象方法,或者只需使用Swift中所有CollectionType都可用的“第一个”

let touch = touches.first as! UITouch

工作得很好!谢谢!