I've got an error that I don't know how to handle. In
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)
}
I get the error "Set" does not have a member named 'anyObject'". I've searched all along the internet and found nothing. I know it is related with some recent changes in Swift but I don't know how to aproach it. Any help will be appreciated!
Try this
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch : UITouch!
touch = touches.first as? UITouch
let touchLocation = touch.locationInNode(self)
sceneTouched(touchLocation)
}
Note that Swift Set type does not have anyObject method. You can either cast it to NSSet and then use anyObject method or simply use first? that is available to all CollectionType in Swift.
let touch = touches.first as! UITouch
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.