<!--
{
  "availability" : [
    "macOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Virtualization",
  "identifier" : "/documentation/Virtualization/VZCustomVirtioDeviceDelegate/customVirtioDeviceSaveState(forRestore:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Virtualization"
    ],
    "preciseIdentifier" : "c:objc(pl)VZCustomVirtioDeviceDelegate(im)customVirtioDeviceSaveStateForRestore:"
  },
  "title" : "customVirtioDeviceSaveState(forRestore:)"
}
-->

# customVirtioDeviceSaveState(forRestore:)

The method the framework calls when a device needs to save its state.

```
optional func customVirtioDeviceSaveState(forRestore device: VZCustomVirtioDevice) -> Data?
```

## Parameters

`device`

The device invoking the delegate method.

## Discussion

Return the state data to save in an <doc://com.apple.documentation/documentation/Foundation/NSData> object.
If there is no state to save, return an empty NSData object ([NSData data]).

If you return `nil` from this method, the save operation fails.

---

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)