Adds a node to the graph.
- Parameter node: The node to add.
- Returns: The key assigned to the newly added node.
- Throws: A `NodeError` if the node cannot be added.
Returns whether the given node can be added to the graph.
This is the non-throwing preflight check for ``addNode(_:)``. Use it
to validate a node — for example, to gate UI affordances — without
modifying the graph.
- Parameter node: The node to test.
- Returns: `true` if calling ``addNode(_:)`` with this node would succeed.
Updates an existing node in the graph.
- Parameters:
- node: The updated node data.
- forKey: The key of the node to update.
- Throws: if the node cannot be updated.
Returns whether the given edge can be added to the graph.
This is the non-throwing preflight check for ``addEdge(_:)``. Use it
to validate a connection — for example, to highlight compatible ports
during drag-and-drop — without modifying the graph.
- Parameter edge: The edge to test.
- Returns: `true` if calling ``addEdge(_:)`` with this edge would succeed.
Removes an edge from the graph.
- Parameter edge: The edge to remove.
- Throws: if the edge cannot be removed.
- Returns: `true` if the edge was found and removed.
Replaces all nodes and edges in the graph with the provided collections.
This bulk operation allows for efficient wholesale replacement of the graph's
structure.
- Parameters:
- nodes: A sequence of nodes and their keys to add to the graph.
- edges: A sequence of edges to add to the graph.
- Throws: An error if the replacement operation fails.
func data(using format: ComputeNodeGraph.Format) throws -> Data
Returns the graph encoded in the specified format.
To reconstruct the graph, pass the data to ``ComputeNodeGraph/init(data:)``.
- Parameter format: The serialization format to use when encoding the
graph.
- Returns: The graph encoded using the specified format.
- Throws: An error if the graph can't be encoded in the requested format.
Creates a graph by decoding a computegraph.
This initializer infers the serialization format from the contents of
`data`, so you can pass data produced by
``ComputeNodeGraph/data(using:)`` regardless of the ``Format`` you chose
when encoding.
- Parameter data: The encoded graph data to decode.
- Throws: An error if `data` isn't a recognized graph format, or if the
contents can't be decoded into a valid graph.
get · iOS 27.0+
edges
TypeScript
get edges(): Array<ComputeNodeGraph_Edge>
Swift declaration
var edges: [ComputeNodeGraph.Edge] { get }
get · iOS 27.0+
nodes
TypeScript
get nodes(): Record<number, ComputeNodeGraph_Node>
Swift declaration
var nodes: [ComputeNodeGraph.NodeID : ComputeNodeGraph.Node]
set · iOS 27.0+
nodes
TypeScript
set nodes(value: Record<number, ComputeNodeGraph_Node>)
Swift declaration
var nodes: [ComputeNodeGraph.NodeID : ComputeNodeGraph.Node]
Returns whether the graph contains the given edge.
- Parameter edge: The edge to look up.
- Returns: `true` if the graph contains the edge; otherwise, `false`.
Returns whether the graph contains a node with the given key.
- Parameter node: The key of the node to look up.
- Returns: `true` if the graph contains the node; otherwise, `false`.
subscript(node: ComputeNodeGraph.NodeID) -> ComputeNodeGraph.Node? { get }
Accesses the node associated with the given key.
- Parameter node: The key identifying the node to retrieve.
- Returns: The node if it exists, or `nil` if no node is associated with the key.