Search code examples
iosswiftnsset

'NSSet?' does not contain a member called 'Generator'


I am overriding the hit test behaviour of a view.

 override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView?
    {
        var touches:NSSet? = event?.allTouches()
        for touch in touches
        {
            //look at each touch
        }
    }

I need to check if the touchphase is began. However I cannot seem to iterate through all the touches.

I get the error

'NSSet?' does not contain a member called 'Generator'

I am assuming this means I cannot iterate an NSSet like I would an array?

Do you know the proper syntax in Swift to iterate an NSSet?


Solution

  • The problem is you're trying to iterate on an optional set. You'll need to unwrap it first.