---
title: "saveMachineStateTo(url:completionHandler:)"
framework: virtualization
role: symbol
role_heading: Instance Method
path: "virtualization/vzvirtualmachine/savemachinestateto(url:completionhandler:)"
---

# saveMachineStateTo(url:completionHandler:)

Saves the state of a VM.

## Declaration

```swift
func saveMachineStateTo(url saveFileURL: URL, completionHandler: @escaping ((any Error)?) -> Void)
```

```swift
func saveMachineStateTo(url saveFileURL: URL) async throws
```

## Parameters

- `saveFileURL`: An doc://com.apple.documentation/documentation/Foundation/NSURL that indicates the location where the framework writes the saved state of the VM.
- `completionHandler`: A block the framework calls after successfully saving the VM or upon returning an error. The error parameter passed to the block is nil if the save was successful.

## Discussion

Discussion Use this method to save a paused VM to a file. You can use the contents of this file later to restore the state of the paused VM. This call fails if the VM isn’t in a paused state or if the Virtualization framework can’t save the VM. If this method fails, the framework returns an error, and the VM state remains unchanged. If this method is successful, the framework writes the file, and the VM state remains unchanged.

## See Also

### Saving and restoring the VM state

- [restoreMachineStateFrom(url:completionHandler:)](virtualization/vzvirtualmachine/restoremachinestatefrom(url:completionhandler:).md)
