'Set' <NSObject> does not have a member named 'anyObject'

user2540538 picture user2540538 · Apr 12, 2015 · Viewed 7.6k times · Source

today i updated xcode with Swift 1.2 my code was working well on Swift 1.1 but when i updated i got this error:

'Set' does not have a member named 'anyObject'

Here's my code:

override public func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
    let location:CGPoint? = touches.anyObject()?.locationInView(self)
    if let loc = location {
        if (!CGRectContainsPoint(ScaleRect(self.bounds, n: 2.0), loc)) {
            self.highlighted = false
        }
    }
}

Does you guys have an idea on how can i fix that please?

Answer

Wojtek Surowka picture Wojtek Surowka · Apr 12, 2015

Use first which is the equivalent of anyObject of NSSet for Swift sets:

touches.first