Though I'm using SpriteKit, this is a general Swift question:
I am creating game classes that will all use SKSpriteNodes (NPC, Player, Powerup, and so on). I want to store SKSpriteNodes as properties on these objects, rather than inheriting from SKSpriteNode (favoring composition over inheritance).
This works great, except I can't capture which game object class was tapped by a user with the touchesBegan function. SKScene's nodeAtPoint only returns the instance of the SKSpriteNode, with no way to know which game object owns it. I can loop through all of my game object instances and compare their sprite nodes to the touched node to create the link I need . . . but that seems very inefficient.
Is there a way to expose the object that 'owns' the property of the touched node? Or another method to do what I'm describing? Or should I just inherit from SKSpriteNode like I see in most example games?