title: Swift/SpriteKit Collision with Custom Class
body: <p>I have a class that creates variables for multiple SpriteNods which looks like this:</p>
  
  <pre><code>class Enemy {
  
  var speed:Float = 0.0
  var guy:SKSpriteNode
  var currentFrame = 0
  var randomFrame = 0
  var moving = false
  var rotationSpeed:CGFloat = 1.0
  var angle = 0.0
  var range = 1.2
  var yPos = CGFloat()
  var rotationDirection:Int = 0
  var preLocation:CGFloat = 0
  var health:Int = 0
  
  init(speed:Float, guy:SKSpriteNode, rotationSpeed:CGFloat, rotationDirection:Int, preLocation:CGFloat, health:Int) {
  
      self.speed = speed
      self.guy = guy
      self.rotationSpeed = rotationSpeed
      self.rotationDirection = rotationDirection
      self.preLocation = preLocation
      self.health = health
  
  
  }
  </code></pre>
  
  <p>A SpriteNode is then applied to the Enemy like this:</p>
  
  <pre><code>func addEnemy(#named: String, speed:Float, yPos: CGFloat, rotationSpeed:CGFloat, rotationDirection:Int, preLocation:CGFloat, health:Int) {
  
      var enemyNode = SKSpriteNode(imageNamed: named)
  
      enemyNode.physicsBody = SKPhysicsBody(texture: enemyNode.texture, alphaThreshold: 0, size: enemyNode.size)
      enemyNode.physicsBody!.affectedByGravity = false
      enemyNode.physicsBody!.categoryBitMask = ColliderType.Enemy.rawValue
      enemyNode.physicsBody!.contactTestBitMask = ColliderType.Hero.rawValue | ColliderType.Enemy.rawValue
      enemyNode.physicsBody!.collisionBitMask = ColliderType.Hero.rawValue | ColliderType.Enemy.rawValue
      enemyNode.physicsBody?.allowsRotation = false
  
      var enemy = Enemy(speed: speed, guy: enemyNode, rotationSpeed: rotationSpeed, rotationDirection: rotationDirection, preLocation: preLocation, health: health)
      enemys.append(enemy)
      enemy.guy.name = named
      resetEnemy(enemyNode, yPos: yPos)
      enemy.yPos = enemyNode.position.y
      addChild(enemyNode)
  
  }
  </code></pre>
  
  <p>Now i have the problem that in the didBeginContact function i only get the SpriteNodes back so i can't get to the enemy specific variables, like health.</p>
  
  <p>So i want to know how i can reference the enemy class to the spritenode, so i can use it in the didBeginContact function.</p>
  
  <p>I hope someone can help me. Thanks.</p>