<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/SKNode/enumerateChildNodes(withName:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SpriteKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SKNode(im)enumerateChildNodesWithName:usingBlock:"
  },
  "title" : "enumerateChildNodes(withName:using:)"
}
-->

# enumerateChildNodes(withName:using:)

Searches the children of the receiving node to perform processing for nodes that share a name.

```
func enumerateChildNodes(withName name: String, using block: @escaping (SKNode, UnsafeMutablePointer<ObjCBool>) -> Void)
```

## Parameters

`name`

The name to search for. This may be either the literal name of the node or a customized search string. See `Searching the Node Tree`.

`block`

A block to execute on nodes that match the `name` parameter. The block has the signature `(node:` [`SKNode`](/documentation/SpriteKit/SKNode) `, stop:` <doc://com.apple.documentation/documentation/Swift/UnsafeMutablePointer> `<` <doc://com.apple.documentation/documentation/ObjectiveC/ObjCBool> `>)`.

## Discussion

This method enumerates the child array in order, searching for nodes whose names match the search parameter. The block is called once for each node that matches the name parameter.

The following Swift code shows how you could enumerate through the child nodes of a scene with a name containing the string `yellow`. Each matching node is hidden until the enumeration finds a node that also contains the string `triangle`. When this node is reached, `stop` is set to <doc://com.apple.documentation/documentation/Swift/true> and the processing stops.

Listing 1. Enumerating child nodes

```swift
scene.enumerateChildNodes(withName: "*yellow*") {
    (node, stop) in
    
    node.run(SKAction.hide())
    
    if let name = node.name, name.contains("triangle") {
        stop.initialize(to: true)
    }
}
```

You can also search by class name using [`enumerateChildNodes(withName:using:)`](/documentation/SpriteKit/SKNode/enumerateChildNodes(withName:using:)). However, for custom classes, you need to specify the fully annotated class name (i.e. the project name followed by the class name). The following Swift code shows a custom class, `SpaceshipNode`, based on [`SKSpriteNode`](/documentation/SpriteKit/SKSpriteNode), and created in a project named `SpaceGame`. The first search fails to return an instance of  `SpaceshipNode` added as a child of `parentNode`:

Listing 2. Enumerating child nodes

```swift
class SpaceshipNode: SKSpriteNode {
}
     
let parentNode = SKNode()
let childNode = SpaceshipNode()
parentNode.addChild(childNode)
     
parentNode.enumerateChildNodes(withName: "SpaceshipNode") {
    node, _ in
    // Unannotated name, returns no results 
}
     
parentNode.enumerateChildNodes(withName: "SpaceGame.SpaceshipNode") {
    node, _ in
    // Annotated name, successfully returns `childNode` 
}
     
parentNode.enumerateChildNodes(withName: "SKSpriteNode") {
    node, _ in
    // Superclass name, successfully returns `childNode` 
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)