Boolean array, NAND of [SKSpritenodes] I'm using spritekit, using on touch to detect what the users has tapped, ie., no collisions, etc.  

I have an array of sprite nodes which in effect is a multi-state boolean switch for now the user can only select one node to be active at a time so the logic looks like:



Node A,  Node B, Node C .........Node M
off       off      off        initial
on        off      off        user touches node A
off       off      on          user touches node C


This code is my working template and would like to reduce a lot of this boilerplate down to something reasonable.

I'm looking for ways that are either faster, more the "Apple Way", more OOP.



    var temp1:SKSpriteNode = SKSpriteNode()
  override func touchesBegan(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?)
  {
    if let touch = touches.first
    {
      let tappedNodes:[sk_Node] = nodes(at: touch.location(in: self) )

      for node in tappedNodes
      {
    switch node.name!
        {
        case "level_1":
          pushd(node: node)
          node.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_1_selected") ], timePerFrame: K1_4.f64_t) )

          temp1 = childNode(withName: "level_2")!
          temp1.run(sk_Action.animate(with: [sk_Texture(imageNamed: "level_2_normal") ], timePerFrame: K1_4.f64_t) )
          popd(node:temp1)

          temp1 = SKSpriteNode()
          temp1 = childNode(withName: "level_3")!
          temp1.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_3_normal") ], timePerFrame: K1_4.f64_t) )
          popd(node:temp1)

    case "level_2":
      pushd(node: node)
      node.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_2_selected") ], timePerFrame: K1_4.f64_t) )

      temp1 = childNode(withName: "level_1")!
      temp1.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_1_normal") ], timePerFrame: K1_4.f64_t) )
      popd(node:temp1)

      temp1 = SKSpriteNode()
      temp1 = childNode(withName: "level_3")!
      temp1.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_3_normal") ], timePerFrame: K1_4.f64_t) )
      popd(node:temp1)

    case "level_3":
      pushd(node: node)
      node.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_3_selected") ], timePerFrame: K1_4.f64_t) )

      temp1 = childNode(withName: "level_2")!
      temp1.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_2_normal") ], timePerFrame: K1_4.f64_t) )
      popd(node:temp1)

      temp1 = SKSpriteNode()
      temp1 = childNode(withName: "level_1")!
      temp1.run( sk_Action.animate(with: [sk_Texture(imageNamed: "level_1_normal") ], timePerFrame: K1_4.f64_t) )
      popd(node:temp1)

} } } }


pushd and popd are SKActions that do some simple scaling up and down.
If it were me, I'd reduce the boiler plate by only putting what's actually changing into the switch statement, and putting everything else outside of it. So here you would only set the texture names in the switch statement. Something like this:

var selectedTextureName : String
var normalTexture1Name : String
var normalTexture2Name : String
var node1Name : String
var node2Name : String
switch node.name!
{
    case "level_1":
        selectedTextureName = "level_1_selected"
        normalTexture1Name = "level_2_normal"
        normalTexture2Name = "level_3_normal"
        node1Name = "level_2"
        node2Name = "level_3"

    case "level_2":
        selectedTextureName = "level_2_selected"
        normalTexture1Name = "level_1_normal"
        normalTexture2Name = "level_3_normal"
        node1Name = "level_1"
        node2Name = "level_3"

    case "level_3":
        selectedTextureName = "level_3_selected"
        normalTexture1Name = "level_1_normal"
        normalTexture2Name = "level_2_normal"
        node1Name = "level_1"
        node2Name = "level_2"
}

pushd(node: node)
node.run( sk_Action.animate(with: [skTexture(imageNamed:selectedTextureName)], timePerFrame: K1_4.f64_t) )

temp1 = childNode(withName: node1Name)!
temp1.run( sk_Action.animate(with: [sk_Texture(imageNamed: normalTexture1Name) ], timePerFrame: K1_4.f64_t) )
popd(node:temp1)

temp1 = SKSpriteNode()
temp1 = childNode(withName: node2Name)!
temp1.run( sk_Action.animate(with: [sk_Texture(imageNamed: normalTexture2Name) ], timePerFrame: K1_4.f64_t) )
popd(node:temp1)