An abstract class used to transform values from one representation to another.
- iOS 3.0+
- macOS 10.3+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
You create a value transformer by subclassing
NSValue and overriding the necessary methods to provide the required custom transformation. You then register the value transformer using the
set method, so that other parts of your app can access it by name with
transformed method to transform a value from one representation into another. If a value transformer designates that its transformation is reversible by returning
allows, you can also use the
reverse 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
UIImage object and return an
NSData object containing the PNG representation of that image.
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.