
Standards was created to enable iOS, tvOS, watchOS and macOS developers that need to support legacy systems (pre iOS 10.0, pre tvOS 10.0, pre watchOS 3.0 and pre macOS 10.12) to use the Measurement API thatβs included in these systemsβs Foundation.
- iOS 8.0
- tvOS 9.0
- watchOS 2.0
- macOS 10.10
Compared to Measurement, Standards has the following features:
- Creating and Converting Standards (e.g. kilometers to miles)
- Calculate with Standards (Operators +, -, *, /)
- Compare Standards
- Measurement Formatting
Compared to Measurement, Standards supports the following Units:
- Acceleration: UnitAcceleration
- Angle: UnitAngle
- Area: UnitArea
- ConcentrationMass: UnitConcentrationMass
- Dispersion: UnitDispersion
- Duration: UnitDuration
- ElectricCharge: UnitElectricCharge
- ElectricCurrent: UnitElectricCurrent
- ElectricPotentialDifference: UnitElectricPotentialDifference
- ElectricResistance: UnitElectricResistance
- Energy: UnitEnergy
- Frequency: UnitFrequency
- FuelEfficiency: UnitFuelEfficiency
- Illuminance: UnitIlluminance
- Length: UnitLength
- Mass: UnitMass
- Power: UnitPower
- Pressure: UnitPressure
- Speed: UnitSpeed (thx @samritchie)
- Temperature: UnitTemperature (thx @samritchie)
- Volume: UnitVolume
Standards is designed to be API-compatible with Foundation on the call site. So you can just use it like you would use Measurement, with one exception:
For compatibility reasons with iOS 10.0+, tvOS 10.0+, watchOS 3.0+ and macOS 10.12+ itβs impractical
to actually call the class Measurement
(b/c you then would always have to namespace it). So just
replace Measurement
with Standard
.
let distance = Standard(value: 106.4, unit: UnitLength.kilometers)
// β 106.4 km
let distanceInMeters = distance.converted(to: .meters)
// β 106400 m
let distanceInMiles = distance.converted(to: .miles)
// β 66.1140591795394 mi
let distanceInFurlongs = distance.converted(to: .furlongs)
// β 528.911158832419 fur
As for now, you can use Carthage or CocoaPods to install Standards using a dependency manager or do it manually.
To integrate Standards into your Xcode project using Carthage, specify it in your Cartfile
:
github "floriankrueger/Standards"
Make sure your Podfile
contains all of the following lines.
use_frameworks!
platform :ios, '8.0'
pod 'Standards'
Then run pod install
.
To do it ‘by hand’ take the following files and add them to your project:
Sources/Standard.swift
Sources/Unit/BasedDimension.swift
Sources/Unit/Dimension.swift
Sources/Unit/Unit.swift
Sources/Conversion/UnitConverter.swift
Sources/Conversion/UnitConverterLinear.swift
And any of the Units that you need:
Sources/Unit/UnitLength.swift
Sources/Unit/UnitArea.swift
Sources/Unit/UnitSpeed.swift
Sources/Unit/UnitTemperature.swift
Thanks for contributing to this project!
Standards is released under the MIT License.

Leave a Reply