---
title: "setVolatileDomain(_:forName:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/userdefaults/setvolatiledomain(_:forname:)"
---

# setVolatileDomain(_:forName:)

Replaces the keys and values in the specified domain with the new keys and values you supply.

## Declaration

```swift
func setVolatileDomain(_ domain: [String : Any], forName domainName: String)
```

## Parameters

- `domain`: A dictionary of keys and values to assign to the domain.
- `domainName`: The name of the domain to update.

## Discussion

Discussion This method removes the existing keys from the specified domain and then adds the new keys you provide. After updating the keys, this method generates a didChangeNotification for registered observers.

## See Also

### Managing domain-specific values

- [persistentDomain(forName:)](foundation/userdefaults/persistentdomain(forname:).md)
- [setPersistentDomain(_:forName:)](foundation/userdefaults/setpersistentdomain(_:forname:).md)
- [volatileDomain(forName:)](foundation/userdefaults/volatiledomain(forname:).md)
- [removePersistentDomain(forName:)](foundation/userdefaults/removepersistentdomain(forname:).md)
- [removeVolatileDomain(forName:)](foundation/userdefaults/removevolatiledomain(forname:).md)
