---
title: "saveToPreferences(completionHandler:)"
framework: networkextension
role: symbol
role_heading: Instance Method
path: "networkextension/nevpnmanager/savetopreferences(completionhandler:)"
---

# saveToPreferences(completionHandler:)

Save the VPN configuration in the Network Extension preferences.

## Declaration

```swift
func saveToPreferences(completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
```

```swift
func saveToPreferences() async throws
```

## Parameters

- `completionHandler`: An optional block that takes an doc://com.apple.documentation/documentation/Foundation/NSError object. If specified, this block will be executed on the caller’s main thread after the save operation is complete. If the configuration could not be saved to the preferences, the error parameter will be set to an NSError object containing details about the error. See NEVPN Errors for a list of possible errors. If the configuration is saved successfully then the error parameter will be set to nil.

## Discussion

Discussion You must call loadFromPreferences(completionHandler:): at least once before calling this method the first time after your app launches.

## See Also

### Related Documentation

- [NEVPNManager](networkextension/nevpnmanager.md)

### Managing VPN configurations

- [shared()](networkextension/nevpnmanager/shared().md)
- [loadFromPreferences(completionHandler:)](networkextension/nevpnmanager/loadfrompreferences(completionhandler:).md)
- [setAuthorization(_:)](networkextension/nevpnmanager/setauthorization(_:).md)
- [removeFromPreferences(completionHandler:)](networkextension/nevpnmanager/removefrompreferences(completionhandler:).md)
