The best way to deal with Measurements and Units in Swift.
Measurements and Units are newly introduced in iOS 10.
Measurement<UnitLength>(value: 3, unit: .kilometers) + Measurement<UnitLength>(value: 4, unit: .kilometers)
3.kilometers + 4.kilometers
SwiftMeasurement supports all units declared in Foundation framework.
Current version is compatible with:
SwiftMeasurement supports multiple methods for installing the library in a project.
CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like SwiftMeasurement in your projects. You can install it with the following command:
$ gem install cocoapods
To integrate SwiftMeasurement into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'SwiftMeasurement'
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate SwiftMeasurement into your Xcode project using Carthage, specify it in your Cartfile
:
github "ken0nek/SwiftMeasurement"
Run carthage
to build the framework and drag the built SwiftMeasurement.framework
into your Xcode project.
// Speed * Duration -> Length
func * (lhs: Measurement<UnitSpeed>, rhs: Measurement<UnitDuration>) -> Measurement<UnitLength> {
let v = lhs.converted(to: .baseUnit()).value * rhs.converted(to: .baseUnit()).value
return Measurement<UnitLength>(value: v, unit: .baseUnit())
}
let duration = 10.hours // 10.0 hr
let speed = 5.kilometersPerHour // 5.0 km/h
(speed * duration).converted(to: .kilometers) // 50.00004 km
link |
Stars: 31 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics