Class

NSDimension

An abstract class representing a dimensional unit of measure. ある次元の寸法単位を表している抽象クラス。

Declaration 宣言

@interface NSDimension : NSUnit

Overview 概要

The Foundation framework provides concrete subclasses for many of the most common types of physical units. Foundationフレームワークは、最も一般的な種類の物理的な単位の多くに対して具象サブクラスを提供します。

Table 1 Apple-provided concrete NSDimension subclasses 表 1 Apple提供の具体的なNSDimensionサブクラス

NSDimension subclass NSDimensionサブクラス

Description 説明

Base unit 基本単位

NSUnitAcceleration

Unit of measure for acceleration 加速度の計測単位

meters per second squared (m/s²) メートル毎秒毎秒(m/s²)

NSUnitAngle

Unit of measure for planar angle and rotation 平面の角度と回転のための計測単位

degrees (°) 度(°)

NSUnitArea

Unit of measure for area 面積の計測単位

square meters (m²) 平方メートル(m²)

NSUnitConcentrationMass

Unit of measure for concentration of mass 質量濃度の計測単位

grams per liter (g/L)

NSUnitDispersion

Unit of measure for dispersion 分散に対する計測単位

parts per million (ppm) 100万分の1(ppm)

NSUnitDuration

Unit of measure for duration of time

seconds (sec) 秒数(sec)

NSUnitElectricCharge

Unit of measure for electric charge 電荷の計測単位

coulombs (C) クーロン (C)

NSUnitElectricCurrent

Unit of measure for electric current 電流の計測単位

amperes (A) アンペア(A)

NSUnitElectricPotentialDifference

Unit of measure for electric potential difference 電位差の計測単位

volts (V) ボルト(V)

NSUnitElectricResistance

Unit of measure for electric resistance 電気抵抗の計測単位

ohms (Ω) オーム(Ω)

NSUnitEnergy

Unit of measure for energy エネルギーの計測単位

joules (J) ジュール(J)

NSUnitFrequency

Unit of measure for frequency 周波数の計測単位

hertz (Hz) ヘルツ(Hz)

NSUnitFuelEfficiency

Unit of measure for fuel efficiency

liters per 100 kilometers (L/100km) リットル毎100キロメートル(L/100km)

NSUnitIlluminance

Unit of measure for illuminance 照度の計測単位

lux (lx) ルクス(lx)

NSUnitInformationStorage

Unit of measure for quantities of information

bytes (b) バイト(b)

NSUnitLength

Unit of measure for length 長さの計測単位

meters (m) メートル(m)

NSUnitMass

Unit of measure for mass 質量の計測単位

kilograms (kg) キログラム(kg)

NSUnitPower

Unit of measure for power 仕事率の計測単位

watts (W) ワット(W)

NSUnitPressure

Unit of measure for pressure 圧力の計測単位

newtons per square meter (N/m²) ニュートン毎平方メートル(N/m²)

NSUnitSpeed

Unit of measure for speed スピードの計測単位

meters per second (m/s) メートル毎秒(m/s)

NSUnitTemperature

Unit of measure for temperature 温度の計測単位

kelvin (K) ケルビン(K)

NSUnitVolume

Unit of measure for volume 体積の計測単位

liters (L) リットル(L)

Each instance of a NSDimension subclass has a converter, which represents the unit in terms of the dimension’s baseUnit. For example, the NSLengthUnit class uses meters as its base unit. The system defines the predefined miles unit by a NSUnitConverterLinear with a 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 unit by a NSUnitConverterLinear with a coefficient of 1.0 because it’s the base unit. NSDimensionサブクラスの各インスタンスは、あるconverterを持ちます、それはその次元の持つbaseUnitに基づく単位を表します。例えば、NSLengthUnitクラスはmetersをそれの基本単位として使います。システムは、あらかじめ定義されるmiles単位をNSUnitConverterLinearによってcoefficient(係数)の1609.34で定義します、それはマイルからメートルへの変換率に相当します(1 mi = 1609.34 m);システムは、あらかじめ定義されるmeters単位をNSUnitConverterLinearによってcoefficientとして1.0を使って定義します、なぜならそれが基本単位だからです。

You typically use an NSDimension subclass in conjunction with the NSMeasurement class to represent specific quantities of a particular unit. あなたは、一般的にNSDimensionサブクラスをNSMeasurementクラスと連携して使って、特定の単位の一定の量を表します。

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. Apple提供の単位に加えて、あなたはあつらえの単位を定義できます。あなたは、あつらえの単位を既存の型の表象とコンバータから初期化することまたは既存の型のクラスメソッドとして実装することが追加の利便性のために行えます。あなたはまた、あなた自身のNSDimensionサブクラスを定義して、まったく新しい単位次元を表せます。

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 initWithSymbol:converter: method. あつらえの単位を定義する最も単純な方法は、既存のNSDimensionサブクラスの新しいインスタンスをinitWithSymbol:converter:メソッドを使って作成することです。

For example, the smoot is a nonstandard unit of length (1 smoot = 1.70180 m). You can create a new instance of NSUnitLength as follows: 例えば、smootは長さの非標準単位です(1 smoot = 1.70180 m)。あなたは、NSUnitLengthの新しいインスタンスを次のように作成できます:


NSUnitConverter *smootsToMeters = [[NSUnitConverterLinear alloc] initWithCoefficient:1.70180];
NSUnitLength *smoots = [[NSUnitLength alloc] initWithSymbol:@"smoot" converter:smootsToMeters];

Extending Existing Dimension Subclasses 既存の次元サブクラスを拡張する

Alternatively, if you use a custom unit extensively throughout an app, consider extending the corresponding NSDimension subclass and adding a static variable. または、あなたがあるあつらえの単位を広範囲にあるアプリの至る所で使うならば、該当するNSDimensionサブクラスを拡張して、ある静的変数の追加を考慮してください。

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 NSUnitSpeed to add a furlongsPerFortnight static variable for convenient access as follows: 例えば、ある速度の測定はファーロング毎2週間であることが可能です(1 fur/ftn = 201.168 m / 1,209,600 s)。あるアプリがこの単位を頻繁に使うようならば、あなたはNSUnitSpeedを拡張して、furlongsPerFortnight静的変数を加えることが便利なアクセスのために可能です、次のように:


@interface NSUnitSpeed ()
+ (NSUnitSpeed *)furlongsPerFortnight;
@end
 
@implementation NSUnitSpeed ()
+ (NSUnitSpeed *)furlongsPerFortnight {
    NSUnitConverter *furlongsPerFortnightToMetersPerSecond = [[NSUnitConverterLinear alloc] initWithCoefficient:201.168 / 1209600.0];
    return [[NSUnitSpeed alloc] initWithSymbol:@"fur/ftn" converter:furlongsPerFortnightToMetersPerSecond];
}
@end

Creating a Custom Dimension Subclass あつらえの次元サブクラスを作成する

You can create a new subclass of NSDimension to describe a new unit dimension. あなたは、NSDimensionの新しいサブクラスを作成して、新しい単位次元を記述できます。

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: 例えば、Foundationフレームワークはどんな単位も放射能に対して定義しません。放射能は、原子核が放射線を発する一連の作用です。放射能のための計測のSI単位はベクレル(Bq)です、それはそこにおいて秒あたり1つの原子核が崩壊するところの放射性物質の量です(1 Bq = 1 s-1)。放射能はまた、よくキュリー(Ci)、1グラムのラジウム226同位体の崩壊に関して定義される単位に基づいて記述されます(1 Ci = 3.7 × 1010 Bq)。あなたはCustomUnitRadioactivityクラスを実装できます、それは放射能の単位の両方とも定義します、以下のように:


@interface CustomUnitRadioactivity: NSDimension
+ (CustomUnitRadioactivity *)becquerels;
+ (CustomUnitRadioactivity *)curies;
@end
 
@implementation CustomRadioactivityUnit
+ (CustomUnitRadioactivity *)becquerels {
    NSUnitConverter *baseUnitConverter = [[NSUnitConverterLinear alloc] initWithCoefficient:1];
    return [[CustomUnitRadioactivity alloc] initWithSymbol:@"Bq" converter:baseUnitConverter];
}
 
+ (CustomUnitRadioactivity *)curies {
    NSUnitConverter *curiesToBecquerels = [[NSUnitConverterLinear alloc] initWithCoefficient:3.7e10];
    return [[CustomUnitRadioactivity alloc] initWithSymbol:@"Ci" converter:curiesToBecquerels];
}
 
+ (instancetype)baseUnit {
    return [self bacquerels];
}
@end

Subclassing Notes サブクラス作成の注意

The system provides NSDimension for subclassing. Although the subclasses listed in Table 1 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). システムは、NSDimensionをサブクラス作成のために提供します。表 1で一覧にされるサブクラスがほとんどの目的に適するとはいえ、あなたはあつらえの単位型を定義したいかもしれません。例えば、あなたはあつらえの単位型をある組立単位、例えば磁束(電位差と時間の積として測定される)を表すために必要とするかもしれません。

To represent dimensionless units, subclass NSUnit directly. 次元なし単位を表すには、直接にNSUnitのサブクラスにしてください。

Methods to Override メソッドのオーバーライド

All subclasses must fully implement the baseUnit method designating the base unit, relative to which you define any additional units. 全てのサブクラスは、基本単位を指名しているbaseUnitメソッドを完全に実装しなければなりません、それに相対してあなたはあらゆる追加単位を定義します。

You must also implement a class method named for the base unit itself, to use interchangeably. For example, the NSUnitIlluminance class defines its baseUnit in terms of the lux (lx) and provides a corresponding lux class method. あなたはまた、基本単位それ自身に名前をつけるクラスメソッドを実装しなければなりません、入れ替えて使うために。例えば、NSUnitIlluminanceクラスは、それのbaseUnitをルクス(lx)に基づいて定義します、そして対応するluxクラスメソッドを提供します。

Alternatives to Subclassing サブクラス作成の代わりとなるもの

As described in Working with Custom Units, you need to create a custom subclass of NSDimension only if you or the system haven’t defined a unit of the desired dimension. You can define a custom unit for an existing NSDimension subclass by either calling the initWithSymbol:converter: method or extending the subclass and adding a corresponding class method. Working with Custom Unitsにおいて記述されるように、あなたがNSDimensionのあつらえのサブクラスを作成する必要があるのは、望む次元の単位をあなたまたはシステムが定義していない場合だけです。あなたは、既存のNSDimensionサブクラスに対してあつらえの単位を定義することが、initWithSymbol:converter:メソッドを呼び出すこと、またはサブクラスを拡張して対応するクラスメソッドを加えることのどちらかによって行えます。

Topics 話題

Creating Dimensions 寸法を作成する

Accessing the Unit Converter 単位コンバータにアクセスする

Accessing the Base Unit 基本単位にアクセスする

Relationships 関係

Inherits From 継承元

Conforms To 次に準拠

See Also 参照

Essentials 要点