An abstract class that provides a description of how to convert a unit to and from the base unit of its dimension.
SDKs
- iOS 10.0+
- macOS 10.12+
- Mac Catalyst 13.0+
- tvOS 10.0+
- watchOS 3.0+
Framework
- Foundation
Declaration
class UnitConverter : NSObject
Overview
For units that can be converted by a scale factor or linear equation, use the concrete subclass Unit
.
Subclassing Notes
NSUnit
is an abstract class that is intended for subclassing. You can implement your own subclass of NSUnit
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 Unit
. You should only create a custom subclass of NSUnit
for units that cannot be converted in this way.