Class

NSValueTransformer

NSValueTransformer is an abstract class that is used by the Cocoa Bindings technology to transform values from one representation to another.

Overview

An application creates a subclass of NSValueTransformer, overriding the necessary methods to provide the required custom transformation.

Example

A relatively trivial value transformer takes an object of type id and returns a string based on the object’€™s class type. This transformer is not reversible as it’s probably unreasonable to transform a class name into an object. The value transformer class you write to accomplish this simple task could look like:

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

Symbols

Using Name-based Registry

+ setValueTransformer:forName:

Registers the provided value transformer with a given identifier.

+ valueTransformerForName:

Returns the value transformer identified by a given identifier.

+ valueTransformerNames

Returns an array of all the registered value transformers.

Getting Information About a Transformer

+ allowsReverseTransformation

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

+ transformedValueClass

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

Using Transformers

- transformedValue:

Returns the result of transforming a given value.

- reverseTransformedValue:

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

Constants

Named Value Transformers

The following named value transformers are defined by NSValueTransformer:

Relationships

Inherits From