title: How to detect when two objects touch in SpriteKit
body: <p>I have found nothing on the internet about how to do this. Im simply trying to run a line of code when to physics body touch. In this case I have an SKSpriteNode with a physics body and another for the ground. When they touch it should run the line of code this is all I have found so far.</p>
  
  <pre><code>    let catGroup:UInt32 = 0x1 &lt;&lt; 0
  let groundGroup:UInt32 = 0x2 &lt;&lt; 1
      cat.physicsBody?.categoryBitMask = catGroup
      cat.physicsBody?.contactTestBitMask = groundGroup
      ground.physicsBody?.categoryBitMask = groundGroup
      ground.physicsBody?.contactTestBitMask = catGroup
  </code></pre>
  
  <p>and here is where I'm confused</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==0 &amp;&amp; secondBody.categoryBitMask==1 {
          print("contact")
      }
  
  }
  </code></pre>
  
  <p>so should i be replacing first body and second body with catGroup and groundGroup? Im not sure how to do this</p>