Alex Pilugin Alex Pilugin - 2 months ago 15
Swift Question

Swift 3. How properly insert variable instead star sign in "//*"

Sorry, there is such code:

if let removedElementName = runCommand.value {
self.enumerateChildNodes(withName: "//*") {
node, stop in node.removeFromParent()
}
}


How properly insert variable removedElementName instead star sign in "//*"

Answer

To remove every child with a given name you can write

self.children
    .filter { $0.name == "nameToRemove" }
    .forEach { $0.removeFromParent() }