我有一个错误,我不知道如何处理。在……里面
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)
}我得到的错误"Set“没有一个名为‘anyObject’的会员。我在网上搜索了所有的内容,没有发现任何东西。我知道这与Swift最近的一些变化有关,但我不知道该如何推广它。任何帮助都将不胜感激!
发布于 2015-07-31 12:37:58
尝尝这个
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch : UITouch!
touch = touches.first as? UITouch
let touchLocation = touch.locationInNode(self)
sceneTouched(touchLocation)
}发布于 2015-07-31 12:38:18
注意,Swift类型没有anyObject方法。您可以将其转换为NSSet,然后使用anyObject方法,或者只需先使用?这在Swift中对所有CollectionType都可用。
let touch = touches.first as! UITouchhttps://stackoverflow.com/questions/31746331
复制相似问题