The type conforms to Hashable, Codable, RawRepresentable, Comparable, ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral, Numeric, and supports all the arithmetic operators.
Codable
The percentage value is encoded as a single value:
struct Foo: Codable {
let alpha: Percentage
}
let foo = Foo(alpha: 1%)
let data = try! JSONEncoder().encode(foo)
let string = String(data: data, encoding: .utf8)!
print(string)
//=> "{\"alpha\":1}"
FAQ
Can you support Carthage and CocoaPods?
No, but you can still use Swift Package Manager for this package even though you mainly use Carthage or CocoaPods.
Percentage
Makes percentages more readable and type-safe, for example, for APIs that currently accept a fraction
Double
.Install
Add the following to
Package.swift
:Or add the package in Xcode.
Usage
See the source for docs.
The type conforms to
Hashable
,Codable
,RawRepresentable
,Comparable
,ExpressibleByFloatLiteral
,ExpressibleByIntegerLiteral
,Numeric
, and supports all the arithmetic operators.Codable
The percentage value is encoded as a single value:
FAQ
Can you support Carthage and CocoaPods?
No, but you can still use Swift Package Manager for this package even though you mainly use Carthage or CocoaPods.
Related