abhuzz / Ampere

Adding multiplication and division to the units of measurement types in Foundation.

Home Page:http://oleb.net/blog/2016/07/unitproduct/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ampere

By Ole Begemann, July 2016

An iOS library that extends Foundation’s units and measurements APIs with type-safe multiplication and division.

Example

let speed = Measurement(value: 20, unit: UnitSpeed.kilometersPerHour)
// → 20.0 km/h
let time = Measurement(value: 2, unit: UnitDuration.hours)
// → 2.0 hr
let distance: Measurement<UnitLength> = speed * time
// → 40000.032 m 🎉

Usage

The library is packaged as an Xcode project that builds an iOS Framework target. I have not (yet) set it up for CocoaPods, Carthage, or the Swift Package Manager. (Although I assume Carthage should build it out of the box.)

Clone the repository, open the project in Xcode, and check out the tests. If you want to use this in your own project in the current form, drag and drop the project file into your Xcode project and add the framework to your linked libraries, or copy the files directly into your project.

Dependencies

None except Swift 3 and Foundation.

More Information

I wrote a series of blog posts about this: Part 1, Part 2, Part 3.

License

MIT License. See LICENSE file for details.

About

Adding multiplication and division to the units of measurement types in Foundation.

http://oleb.net/blog/2016/07/unitproduct/

License:MIT License


Languages

Language:Swift 98.6%Language:Objective-C 1.4%