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


You create a value transformer by subclassing NSValueTransformer 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 valueTransformerForName:.

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 YES 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.

@interface ClassNameTransformer: NSValueTransformer {}
@implementation ClassNameTransformer
+ (Class)transformedValueClass { 
    return [NSString class]; 
+ (BOOL)allowsReverseTransformation { 
    return NO; 
- (id)transformedValue:(id)value {
    return (value == nil) ? nil : NSStringFromClass([value class]);


Using the Name-Based Registry


Registers the provided value transformer with a given identifier.


Returns the value transformer identified by a given identifier.


Returns an array of all the registered value transformers.


Named value transformers defined by NSValueTransformer.

Getting Information About a Transformer


Returns a Boolean value that indicates whether the receiver can reverse a transformation.


Returns the class of the value returned by the receiver for a forward transformation.

Transforming Values


Returns the result of transforming a given value.


Returns the result of the reverse transformation of a given value.


Inherits From

See Also

Value Wrappers and Transformations


An object wrapper for primitive scalar numeric values.


A simple container for a single C or Objective-C data item.