now with swift 2.0, IOS 8.3 this code doesn't work anymore. 'Set' does not have a member named 'allObjects'
public override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
var touch: UITouch = event.allTouches()?.allObjects.last as UITouch!
}
I tried a lot of stuffs but nothing seems to work, any idea ?
Thanks
Swift 1.2 has introduced a native Set
type, but unlike NSSet
it doesn't have the anyObject
method. You have a couple of options. You can use the first()
method or you can take advantage of the ability to bridge a Swift Set to NSSet -
let touch = touches.first() as? UITouch
or
let touchesSet=touches as NSSet
let touch=touchesSet.anyObject() as? UITouch