title: How to know which SKSpriteNode is affected by collision detection in Swift?
body: <p><strong>Situation:</strong> I have two or more ships on my iOS screen. Both have different attributes like name, size, hitpoints and score points. They are displayed as <code>SKSpriteNodes</code> and each one has added a <code>physicsBody</code>.</p>
  
  <p>At the moment those extra attributes are variables of an extended <code>SKSpriteNode</code> class.</p>
  
  <pre><code>import SpriteKit    
  class ship: SKSpriteNode {
              var hitpoints: Int = nil?
              var score: Int = nil?
  
          func createPhysicsBody(){
              self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width / 2)
              self.physicsBody?.dynamic = true
              ...
          }
      }
  </code></pre>
  
  <p>In this 'game' you can shoot at those ships and as soon as a bullet hits a ship, you get points. 'Hits a ship' is detected by collision.</p>
  
  <pre><code>func didBeginContact(contact: SKPhysicsContact){    
      switch(contact.bodyA.categoryBitMask + contact.bodyB.categoryBitMask){
          case shipCategory + bulletCategory:
              contactShipBullet(contact.bodyA, bodyB: contact.bodyB)
              break;
          default:
              break;
      }
  }
  </code></pre>
  
  <p><strong>Problem:</strong> Collision detection just returns a physicsBody and I do not know how to get my extended <code>SKSpriteNode</code> class just by this physicsBody.</p>
  
  <p><strong>Thoughts:</strong> Is it a correct way to extend <code>SKSpriteNode</code> to get my objects like a ship to life? When I add a ship to my screen it looks like:</p>
  
  <pre><code>var ship = Ship(ship(hitpoints: 1, score: 100), position: &lt;CGPosition&gt;)
  self.addChild(ship)
  </code></pre>
  
  <p>Or is this just a wrong approach and there is a much better way to find out which object with stats so and so is hit by a bullet thru collision detection?</p>
  
  <p>This question is similar to my other <a href="https://stackoverflow.com/questions/31772869/how-to-get-skspritenode-by-physicsbody">question</a> - I just want ask this in broader sense.</p>