<!--
{
  "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/UnitConverterLinear",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSUnitConverterLinear"
  },
  "title" : "UnitConverterLinear"
}
-->

# UnitConverterLinear

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

```
class UnitConverterLinear
```

## Overview

A linear equation for unit conversion takes the form `y = mx + b`, such that the following is true:

- `y` is the value in terms of the base unit of the dimension.
- `m` is the known coefficient to use for this unit’s conversion.
- `x` is the value in terms of the unit on which you call this method.
- `b` is the known constant to use for this unit’s conversion.

The `baseUnitValueFromValue:` method performs the conversion in the form of `y = mx + b`, where `x` represents the value passed in and `y` represents the value returned. The `valueFromBaseUnitValue:` method performs the inverse conversion in the form of `x = (y - b) / m`, where `y` represents the value passed in and `x` represents the value returned.

For example, consider the [`fahrenheit`](/documentation/Foundation/UnitTemperature/fahrenheit) unit that [`UnitTemperature`](/documentation/Foundation/UnitTemperature) defines. The [`baseUnitValue(fromValue:)`](/documentation/Foundation/UnitConverter/baseUnitValue(fromValue:)) method calculates the value in the base unit, [`kelvin`](/documentation/Foundation/UnitTemperature/kelvin), using the formula `K = (0.55555555555556) × °F + 255.37222222222427`. The [`value(fromBaseUnitValue:)`](/documentation/Foundation/UnitConverter/value(fromBaseUnitValue:)) method calculates the value in [`fahrenheit`](/documentation/Foundation/UnitTemperature/fahrenheit) using the formula `°F = (K — 255.37222222222427) / (0.55555555555556)`, where the [`coefficient`](/documentation/Foundation/UnitConverterLinear/coefficient) is `(0.55555555555556)` and the [`constant`](/documentation/Foundation/UnitConverterLinear/constant) is `255.37222222222427`.

```objc
NSUnitConverter *kelvinToFahrenheit = [[NSUnitConverterLinear alloc] initWithCoefficient:0.55555555555556 constant:255.37222222222427];
```

Units that perform conversion using only a scale factor have a [`coefficient`](/documentation/Foundation/UnitConverterLinear/coefficient) equal to the scale factor and a [`constant`](/documentation/Foundation/UnitConverterLinear/constant) equal to `0`. For example, consider the [`kilometers`](/documentation/Foundation/UnitLength/kilometers) unit [`UnitLength`](/documentation/Foundation/UnitLength) defines. The [`baseUnitValue(fromValue:)`](/documentation/Foundation/UnitConverter/baseUnitValue(fromValue:)) method calculates the value in meters using the formula `valueInMeters = 1000 * valueInKilometers + 0`. The [`value(fromBaseUnitValue:)`](/documentation/Foundation/UnitConverter/value(fromBaseUnitValue:)) calculates the value in kilometers using the formula `valueInKilometers = (valueInMeters - 0) / 1000`, where the coefficient is `1000` and the constant is `0`.

```objc
NSUnitConverterLinear *kilometersToMeters = [[NSUnitConverterLinear alloc] initWithCoefficient:1000.0 constant:0.0];
```

## Topics

### Accessing Linear Parameters

[`coefficient`](/documentation/Foundation/UnitConverterLinear/coefficient)

The coefficient to use in the linear unit conversion calculation.

[`constant`](/documentation/Foundation/UnitConverterLinear/constant)

The constant to use in the linear unit conversion calculation.

### Creating Unit Converters

[`-  initWithCoefficient:`](/documentation/Foundation/UnitConverterLinear/init(coefficient:))

Initializes the unit converter with the coefficient you specify.

[`-  initWithCoefficient:constant:`](/documentation/Foundation/UnitConverterLinear/init(coefficient:constant:))

Creates a unit converter with the coefficient and constant you specify.

## Relationships

### Inherits From

[`UnitConverter`](/documentation/Foundation/UnitConverter)

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

---

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)