import SpriteKit
class MyScene: SKScene, SKPhysicsContactDelegate {
override func didMove(to view: SKView) {
...
physicsWorld.contactDelegate = self
}
func didBegin(_ contact: SKPhysicsContact) {
guard let name1 = contact.bodyA.node?.name else {return}
guard let name2 = contact.bodyB.node?.name else {return}
// logic deal with the contact
}
}