An abstract class that provides a description of how to convert a unit to and from the base unit of its dimension.


class UnitConverter : NSObject


For units that can be converted by a scale factor or linear equation, use the concrete subclass UnitConverterLinear.

Subclassing Notes

NSUnitConverter is an abstract class that is intended for subclassing. You can implement your own subclass of NSUnitConverter to convert between units according to any desired mapping function. For example, units may be converted using a logarithmic, exponential, or quantile scale.

Methods to Override

All subclasses must fully implement the following methods:

Alternatives to Subclassing

As stated above, most physical units can be converted using a linear equation with UnitConverterLinear. You should only create a custom subclass of NSUnitConverter for units that cannot be converted in this way.


Converting Between Units

func baseUnitValue(fromValue: Double) -> Double

For a given unit, returns the specified value of that unit in terms of the base unit of its dimension.

func value(fromBaseUnitValue: Double) -> Double

For a given unit, returns the specified value of the base unit in terms of that unit.


Inherits From

Conforms To

See Also


class UnitConverterLinear

A description of how to convert between units using a linear equation.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software