---
title: ValueTransformer
framework: foundation
role: symbol
role_heading: Class
path: foundation/valuetransformer
---

# ValueTransformer

An abstract class used to transform values from one representation to another.

## Declaration

```swift
class ValueTransformer
```

## Overview

Overview You create a value transformer by subclassing ValueTransformer and overriding the necessary methods to provide the required custom transformation. You then register the value transformer using the setValueTransformer(_:forName:) method, so that other parts of your app can access it by name with init(forName:). Use the transformedValue(_:) method to transform a value from one representation into another. If a value transformer designates that its transformation is reversible by returning true for allowsReverseTransformation(), you can also use the reverseTransformedValue(_:) to perform the transformation in reverse. For example, reversing the characters in a string is a reversible operation, whereas changing the characters in a string to be uppercase is a nonreversible operation. A value transformer can take inputs of one type and return a value of a different type. For example,  a value transformer could take an NSImage or UIImage object and return an NSData object containing the PNG representation of that image. Example Usage The following example defines a new value transformer that takes an object and returns a string based on the object’s class type. This transformer isn’t reversible because it doesn’t make sense to transform a class name into an object.

## Topics

### Using the Name-Based Registry

- [setValueTransformer(_:forName:)](foundation/valuetransformer/setvaluetransformer(_:forname:).md)
- [init(forName:)](foundation/valuetransformer/init(forname:).md)
- [valueTransformerNames()](foundation/valuetransformer/valuetransformernames().md)
- [NSValueTransformerName](foundation/nsvaluetransformername.md)

### Getting Information About a Transformer

- [allowsReverseTransformation()](foundation/valuetransformer/allowsreversetransformation().md)
- [transformedValueClass()](foundation/valuetransformer/transformedvalueclass().md)

### Transforming Values

- [transformedValue(_:)](foundation/valuetransformer/transformedvalue(_:).md)
- [reverseTransformedValue(_:)](foundation/valuetransformer/reversetransformedvalue(_:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [NSSecureUnarchiveFromDataTransformer](foundation/nssecureunarchivefromdatatransformer.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Value Wrappers and Transformations

- [NSNumber](foundation/nsnumber.md)
- [NSValue](foundation/nsvalue.md)
