<!--
{
  "availability" : [
    "macOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Virtualization",
  "identifier" : "/documentation/Virtualization/VZVmnetNetworkDeviceAttachment/init(network:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Virtualization"
    ],
    "preciseIdentifier" : "c:objc(cs)VZVmnetNetworkDeviceAttachment(im)initWithNetwork:"
  },
  "title" : "init(network:)"
}
-->

# init(network:)

Creates the attachment and configures it with the specified data.

```
init(network: vmnet_network_ref)
```

## Parameters

`network`

The logical network object

## Return Value

An initialized `VZVmnetNetworkDeviceAttachment` object, or `nil` if there was an error.

## Discussion

To ensure proper isolation between application processes, a virtual machine (VM) can only use the `network` that the same application process creates. If an application’s VM tries to use a `network` that another application’s VM creates, initialization fails.

For more information on vmnet configuration requirements and restrictions, see <doc://com.apple.documentation/documentation/vmnet>

The following example demonstrates how to create and initialize a custom network using `VZVmnetNetworkDeviceAttachment`.

```swift
let status = UnsafeMutablePointer<vmnet_return_t>.allocate(capacity: 1)
let network_configuration = vmnet_network_configuration_create(operating_modes_t.VMNET_SHARED_MODE, status);
if (network_configuration == nil) {
    // Handle error return `status`.
}

let network = vmnet_network_create(network_configuration!, status)
if (network == nil) {
    // Handle error return `status`.
}

let virtioNetworkDevice = VZVirtioNetworkDeviceConfiguration()
virtioNetworkDevice.attachment = try! VZVmnetNetworkDeviceAttachment(network: network!)       
```

---

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)