11

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?

Airspeed Velocity
  • 40,491
  • 8
  • 113
  • 118
user2540538
  • 205
  • 3
  • 8
  • http://stackoverflow.com/questions/28771896/overriding-method-with-selector-touchesbeganwithevent-has-incompatible-type, http://stackoverflow.com/questions/29566861/event-touchesforview-anyobject-not-working-in-xcode-6-3, http://stackoverflow.com/questions/29593411/swift-1-2-replacement-for-nsset-anyobject – Martin R Apr 12 '15 at 21:17

1 Answers1

33

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

touches.first
Wojtek Surowka
  • 20,535
  • 4
  • 44
  • 51