Swiftpack.co - ken0nek/SwiftMeasurement as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ken0nek.
ken0nek/SwiftMeasurement 0.4.1
The best way to deal with Measurements and Units in Swift.
⭐️ 31
🕓 2 years ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/ken0nek/SwiftMeasurement.git", from: "0.4.1")

SwiftMeasurement

Version License Platforms

The best way to deal with Measurements and Units in Swift.

Measurements and Units are newly introduced in iOS 10.

Usage

  • before

Measurement<UnitLength>(value: 3, unit: .kilometers) + Measurement<UnitLength>(value: 4, unit: .kilometers)
  • after

3.kilometers + 4.kilometers

SwiftMeasurement supports all units declared in Foundation framework.

  • UnitLength
  • UnitFuelEfficiency
  • UnitElectricResistance
  • UnitIlluminance
  • UnitDispersion
  • UnitElectricCharge
  • UnitVolume
  • UnitEnergy
  • UnitAngle
  • UnitDuration
  • UnitTemperature
  • UnitFrequency
  • UnitPower
  • UnitElectricCurrent
  • UnitElectricPotentialDifference
  • UnitAcceleration
  • UnitSpeed
  • UnitArea
  • UnitMass
  • UnitConcentrationMass
  • UnitPressure

Requirements

Current version is compatible with:

  • Swift 5.0+
  • masOS 10.12 or later
  • iOS 10.0 or later
  • watchOS 3.0 or later
  • tvOS 10.0 or later

Installation

SwiftMeasurement supports multiple methods for installing the library in a project.

Installation with CocoaPods

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

Podfile

To integrate SwiftMeasurement into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SwiftMeasurement'

Then, run the following command:

$ pod install

Installation with Carthage

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.

Future features

  • ☐ Describe relations between dimentions. [L, M, T, L/T, L/T^2, etc...]

// 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

GitHub

link
Stars: 31
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.4.1
2 years ago
  • watchOS and tvOS support

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics