Questions Questions - 1 year ago 91
Swift Question

Removing an SKSpriteNode by name

I have an object called "color" and I give each spawned "color" a name such as:




I want to know how can I remove the object "color" by its

extension using
in an if statement?

Basically the spawning code produces "red", "blue" or "green" then I want to have an if statement that runs when the user uses the keyboard.

if str?.lowercaseString == {
"remove the color with that name extension".removeFromParent()

basically I want to remove the color with the name extension (red, blue or green) that matched the "subject"variable in the if statement :)

Answer Source

since you already have a color object that you are comparing and you already have something to compare it to (subject), you have all the pieces you need. You just don't include the name property when removing from parent.

if subject == {