<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKGraph/init(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKGraph(im)initWithNodes:"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Initializes a graph with the specified list of nodes.

```
init(_ nodes: [GKGraphNode])
```

## Parameters

`nodes`

An array of graph node objects—instances of [`GKGraphNode`](/documentation/GameplayKit/GKGraphNode) or of one of its subclasses containing geometry information.

## Return Value

A new graph object.

## Discussion

The nodes in the array need not already be connected—you can connect nodes after adding them to the graph using the [`connectToLowestCostNode(node:bidirectional:)`](/documentation/GameplayKit/GKGraph/connectToLowestCostNode(node:bidirectional:)) method on the graph itself or the addConnection:bidirectional: method on individual nodes. Using the [`findPath(from:to:)`](/documentation/GameplayKit/GKGraph/findPath(from:to:)) method requires connections between nodes.

For more information, see [GameplayKit Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/index.html#//apple_ref/doc/uid/TP40015172).

---

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)