<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Dimension",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDimension"
  },
  "title" : "Dimension"
}
-->

# Dimension

An abstract class representing a dimensional unit of measure.

```
class Dimension
```

## Overview

The Foundation framework provides concrete subclasses for many of the most common types of physical units.

Table 1: [`Dimension`](/documentation/Foundation/Dimension) subclasses.

|NSDimension subclass                                                                   |Description                                      |Base unit                          |
|---------------------------------------------------------------------------------------|-------------------------------------------------|-----------------------------------|
|``doc://com.apple.foundation/documentation/Foundation/UnitAcceleration``               |Unit of measure for acceleration                 |meters per second squared (m/s²)   |
|``doc://com.apple.foundation/documentation/Foundation/UnitAngle``                      |Unit of measure for planar angle and rotation    |degrees (°)                        |
|``doc://com.apple.foundation/documentation/Foundation/UnitArea``                       |Unit of measure for area                         |square meters (m²)                 |
|``doc://com.apple.foundation/documentation/Foundation/UnitConcentrationMass``          |Unit of measure for concentration of mass        |grams per liter (g/L)              |
|``doc://com.apple.foundation/documentation/Foundation/UnitDispersion``                 |Unit of measure for dispersion                   |parts per million (ppm)            |
|``doc://com.apple.foundation/documentation/Foundation/UnitDuration``                   |Unit of measure for duration of time             |seconds (sec)                      |
|``doc://com.apple.foundation/documentation/Foundation/UnitElectricCharge``             |Unit of measure for electric charge              |coulombs (C)                       |
|``doc://com.apple.foundation/documentation/Foundation/UnitElectricCurrent``            |Unit of measure for electric current             |amperes (A)                        |
|``doc://com.apple.foundation/documentation/Foundation/UnitElectricPotentialDifference``|Unit of measure for electric potential difference|volts (V)                          |
|``doc://com.apple.foundation/documentation/Foundation/UnitElectricResistance``         |Unit of measure for electric resistance          |ohms (Ω)                           |
|``doc://com.apple.foundation/documentation/Foundation/UnitEnergy``                     |Unit of measure for energy                       |joules (J)                         |
|``doc://com.apple.foundation/documentation/Foundation/UnitFrequency``                  |Unit of measure for frequency                    |hertz (Hz)                         |
|``doc://com.apple.foundation/documentation/Foundation/UnitFuelEfficiency``             |Unit of measure for fuel efficiency              |liters per 100 kilometers (L/100km)|
|``doc://com.apple.foundation/documentation/Foundation/UnitIlluminance``                |Unit of measure for illuminance                  |lux (lx)                           |
|``doc://com.apple.foundation/documentation/Foundation/UnitInformationStorage``         |Unit of measure for quantities of information    |bytes (b)                          |
|``doc://com.apple.foundation/documentation/Foundation/UnitLength``                     |Unit of measure for length                       |meters (m)                         |
|``doc://com.apple.foundation/documentation/Foundation/UnitMass``                       |Unit of measure for mass                         |kilograms (kg)                     |
|``doc://com.apple.foundation/documentation/Foundation/UnitPower``                      |Unit of measure for power                        |watts (W)                          |
|``doc://com.apple.foundation/documentation/Foundation/UnitPressure``                   |Unit of measure for pressure                     |newtons per square meter (N/m²)    |
|``doc://com.apple.foundation/documentation/Foundation/UnitSpeed``                      |Unit of measure for speed                        |meters per second (m/s)            |
|``doc://com.apple.foundation/documentation/Foundation/UnitTemperature``                |Unit of measure for temperature                  |kelvin (K)                         |
|``doc://com.apple.foundation/documentation/Foundation/UnitVolume``                     |Unit of measure for volume                       |liters (L)                         |

Each instance of a [`Dimension`](/documentation/Foundation/Dimension) subclass has a [`converter`](/documentation/Foundation/Dimension/converter), which represents the unit in terms of the dimension’s [`baseUnit()`](/documentation/Foundation/Dimension/baseUnit()). For example, the `NSLengthUnit` class uses [`meters`](/documentation/Foundation/UnitLength/meters) as its base unit. The system defines the predefined [`miles`](/documentation/Foundation/UnitLength/miles) unit by a [`UnitConverterLinear`](/documentation/Foundation/UnitConverterLinear) with a [`coefficient`](/documentation/Foundation/UnitConverterLinear/coefficient) of `1609.34`, which corresponds to the conversion ratio of miles to meters (1 mi = 1609.34 m); the system defines the predefined [`meters`](/documentation/Foundation/UnitLength/meters) unit by a [`UnitConverterLinear`](/documentation/Foundation/UnitConverterLinear) with a [`coefficient`](/documentation/Foundation/UnitConverterLinear/coefficient) of `1.0` because it’s the base unit.

You typically use an `NSDimension` subclass in conjunction with the [`NSMeasurement`](/documentation/Foundation/NSMeasurement) class to represent specific quantities of a particular unit.

### Working with Custom Units

In addition to the Apple-provided units, you can define custom units. You can initialize custom units from a symbol and converter of an existing type or implemented as a class method of an existing type for additional convenience. You can also define your own `NSDimension` subclass to represent an entirely new unit dimension.

#### Initializing a Custom Unit with a Specified Symbol and Definition

The simplest way to define a custom unit is to create a new instance of an existing `NSDimension` subclass using the [`init(symbol:converter:)`](/documentation/Foundation/Dimension/init(symbol:converter:)) method.

For example, the *smoot* is a nonstandard unit of length (1 smoot = 1.70180 m). You can create a new instance of [`UnitLength`](/documentation/Foundation/UnitLength) as follows:

```swift
let smoots = UnitLength(symbol: "smoot", converter: UnitConverterLinear(coefficient: 1.70180))
```

#### Extending Existing Dimension Subclasses

Alternatively, if you use a custom unit extensively throughout an app, consider extending the corresponding [`Dimension`](/documentation/Foundation/Dimension) subclass and adding a static variable.

For example, a measurement of speed can be furlongs per fortnight (1 fur/ftn = 201.168 m / 1,209,600 s). If an app makes frequent use of this unit, you can extend [`UnitSpeed`](/documentation/Foundation/UnitSpeed) to add a `furlongsPerFortnight` static variable for convenient access as follows:

```swift
extension UnitSpeed {
    static let furlongPerFortnight = UnitSpeed(symbol: "fur/ftn", converter: UnitConverterLinear(coefficient: 201.168 / 1209600.0))
}
```

#### Creating a Custom Dimension Subclass

You can create a new subclass of [`Dimension`](/documentation/Foundation/Dimension) to describe a new unit dimension.

For example, the Foundation framework doesn’t define any units for radioactivity. Radioactivity is the process by which the nucleus of an atom emits radiation. The SI unit of measure for radioactivity is the becquerel (Bq), which is the quantity of radioactive material in which one nucleus decays per second (1 Bq = 1 s-1). Radioactivity is also commonly described in terms of curies (Ci), a unit defined relative to the decay of one gram of the radium-226 isotope (1 Ci = 3.7 × 1010 Bq). You can implement a `CustomUnitRadioactivity` class that defines both units of radioactivity as follows:

```swift
class CustomRadioactivityUnit: Dimension {
    static let becquerel = CustomRadioactivityUnit(symbol: "Bq", UnitConverterLinear(coefficient: 1.0))
    static let curie = CustomRadioactivityUnit(symbol: "Ci", UnitConverterLinear(coefficient: 3.7e10))
    
    static let baseUnit = self.becquerel
}
```

### Subclassing Notes

The system provides [`Dimension`](/documentation/Foundation/Dimension) for subclassing. Although the subclasses listed in Table 1 above are suitable for most purposes, you may want to define a custom unit type. For instance, you may need a custom unit type to represent a derived unit, such as magnetic flux (measured as the product of electric potential difference and time).

To represent dimensionless units, subclass [`Unit`](/documentation/Foundation/Unit) directly.

#### Methods to Override

All subclasses must fully implement the [`baseUnit()`](/documentation/Foundation/Dimension/baseUnit()) method designating the base unit, relative to which you define any additional units.

You must also implement a class method named for the base unit itself, to use interchangeably. For example, the [`UnitIlluminance`](/documentation/Foundation/UnitIlluminance) class defines its [`baseUnit()`](/documentation/Foundation/Dimension/baseUnit()) in terms of the lux (lx) and provides a corresponding [`lux`](/documentation/Foundation/UnitIlluminance/lux) class method.

#### Alternatives to Subclassing

As described in [`Working with Custom Units`](/documentation/Foundation/Dimension#Working-with-Custom-Units), you need to create a custom subclass of [`Dimension`](/documentation/Foundation/Dimension) only if you or the system haven’t defined a unit of the desired dimension. You can define a custom unit for an existing [`Dimension`](/documentation/Foundation/Dimension) subclass by either calling the [`init(symbol:converter:)`](/documentation/Foundation/Dimension/init(symbol:converter:)) method or extending the subclass and adding a corresponding class method.

## Topics

### Creating Dimensions

[`init(symbol:converter:)`](/documentation/Foundation/Dimension/init(symbol:converter:))

Initializes a dimensional unit with the symbol and unit converter you specify.

### Accessing the Unit Converter

[`converter`](/documentation/Foundation/Dimension/converter)

The unit converter that represents the unit in terms of the dimension’s base unit.

### Accessing the Base Unit

[`baseUnit()`](/documentation/Foundation/Dimension/baseUnit())

Returns the base unit.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)