Standards 0.2

Standards 0.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2017
SwiftSwift Version 3.1
SPMSupports SPM

Maintained by Florian Krüger.



  • By
  • Florian Krüger

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.

Compatibility

  • [x] iOS 8.0
  • [x] tvOS 9.0
  • [x] watchOS 2.0
  • [x] macOS 10.10

Features

Compared to Measurement, Standards has the following features:

  • [x] Creating and Converting Standards (e.g. kilometers to miles)
  • [ ] Calculate with Standards (Operators +, -, *, /)
  • [x] Compare Standards
  • [ ] Measurement Formatting

Compared to Measurement, Standards supports the following Units:

Remarks

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.

Basic Usage

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 

Installation

As for now, you can use Carthage or CocoaPods to install Standards using a dependency manager or do it manually.

Manually

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

Contributors

Thanks for contributing to this project!

License

Standards is released under the MIT License.