Searches the children of the receiving node to perform processing for nodes that share a name.
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 3.0+
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.
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 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
true and the processing stops.
You can also search by class name using
enumerate. 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 code shows a custom class,
Spaceship, based on
SKSprite, and created in a project named
Space. The first search fails to return an instance of
Spaceship added as a child of