title: How may i detect contact and collision correctly? Swift iOS SKScene
body: <p>The problem is i can't detect the collision //or contact in any way i have found on the internet</p>
  
  <p>This is my code:</p>
  
  <p>The declaration of my masks:</p>
  
  <pre><code>private let ballCategory : UInt32 = 0x1 &lt;&lt; 0
  private let holeCategory : UInt32 = 0x1 &lt;&lt; 1
  </code></pre>
  
  <p>The adding of both the hole and the ball:</p>
  
  <pre><code>func addHole(#size : CGSize) {
  
      let actionMoveDown = SKAction.moveToY(CGRectGetMidY(self.frame)-500, duration: 4.7)
      let hole = shapedHoles()
      let UT = UTIL()
      var position:CGFloat
  
  
      let randomPosition = UT.randomNumberWith(Min: 1, Max: 3)
  
      switch randomPosition{
      case 1:
          position = CGRectGetMidX(self.frame)
      case 2:
          position = CGRectGetMidX(self.frame)+size.width
  
      default:
          position = CGRectGetMidX(self.frame)-(size.width)
  
      }
  
  
  
      var createdHole = hole.createHoleAtPosition(position: CGPointMake(position ,CGRectGetMaxY(self.frame) + (size.height/2)),size: size )//CGSizeMake(CGRectGetMaxX(self.frame)/3 - 10, 70)
  
      createdHole.physicsBody = SKPhysicsBody(rectangleOfSize: createdHole.frame.size)
      createdHole.physicsBody?.categoryBitMask = holeCategory
      createdHole.physicsBody?.collisionBitMask = 0
      createdHole.physicsBody?.contactTestBitMask = ballCategory
      createdHole.physicsBody?.affectedByGravity = false
      createdHole.physicsBody?.dynamic = false
  
  
      lastHolePosition = randomPosition
  
      createdHole .runAction(actionMoveDown)
  
      self.addChild(createdHole)
  
  
  
  }
  
  func addSphere(){
      let mainCharacterController = circle()
      let character: (SKNode) = mainCharacterController.createCircleAtPosition(position: CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinY(self.frame)+100))
  
  
      character.physicsBody = SKPhysicsBody(circleOfRadius: character.frame.size.height/2)
      character.physicsBody?.categoryBitMask = ballCategory
      character.physicsBody?.collisionBitMask = 0
      character.physicsBody?.contactTestBitMask = holeCategory
      character.physicsBody?.affectedByGravity = false
      character.physicsBody?.dynamic = false
  
  
      self.addChild(character)
  
  
  }    func addHole(#size : CGSize) {
  
      let actionMoveDown = SKAction.moveToY(CGRectGetMidY(self.frame)-500, duration: 4.7)
      let hole = shapedHoles()
      let UT = UTIL()
      var position:CGFloat
  
  
      let randomPosition = UT.randomNumberWith(Min: 1, Max: 3)
  
      switch randomPosition{
      case 1:
          position = CGRectGetMidX(self.frame)
      case 2:
          position = CGRectGetMidX(self.frame)+size.width
  
      default:
          position = CGRectGetMidX(self.frame)-(size.width)
  
      }
  
  
  
      var createdHole = hole.createHoleAtPosition(position: CGPointMake(position ,CGRectGetMaxY(self.frame) + (size.height/2)),size: size )//CGSizeMake(CGRectGetMaxX(self.frame)/3 - 10, 70)
  
      createdHole.physicsBody = SKPhysicsBody(rectangleOfSize: createdHole.frame.size)
      createdHole.physicsBody?.categoryBitMask = holeCategory
      createdHole.physicsBody?.collisionBitMask = 0
      createdHole.physicsBody?.contactTestBitMask = ballCategory
      createdHole.physicsBody?.affectedByGravity = false
      createdHole.physicsBody?.dynamic = false
  
  
      lastHolePosition = randomPosition
  
      createdHole .runAction(actionMoveDown)
  
      self.addChild(createdHole)
  
  
  
  }
  
  func addSphere(){
      let mainCharacterController = circle()
      let character: (SKNode) = mainCharacterController.createCircleAtPosition(position: CGPointMake(CGRectGetMidX(self.frame), CGRectGetMinY(self.frame)+100))
  
  
      character.physicsBody = SKPhysicsBody(circleOfRadius: character.frame.size.height/2)
      character.physicsBody?.categoryBitMask = ballCategory
      character.physicsBody?.collisionBitMask = 0
      character.physicsBody?.contactTestBitMask = holeCategory
      character.physicsBody?.affectedByGravity = false
      character.physicsBody?.dynamic = false
  
  
      self.addChild(character)
  
  
  }
  </code></pre>
  
  <p>And last but not least the didBeginContactMethod</p>
  
  <pre><code>func didBeginContact(contact: SKPhysicsContact) {
  
      var firstBody: SKPhysicsBody!
      var secondBody: SKPhysicsBody!
  
      if contact.bodyA.categoryBitMask &lt; contact.bodyB.categoryBitMask {
          firstBody = contact.bodyA
          secondBody = contact.bodyB
      }
      else {
          firstBody = contact.bodyB
          secondBody = contact.bodyA
      }
  
      if (firstBody.categoryBitMask &amp; holeCategory) != 0 &amp;&amp;
          (secondBody.categoryBitMask &amp; ballCategory) != 0 {
          println("HO")
      }
  }
  </code></pre>
  
  <p>Thank you and hope you know what is happening, and if you need any extra code just comment it</p>