Percentage alternatives and similar libraries
Based on the "Utility" category.
Alternatively, view Percentage alternatives based on common mentions on social networks and blogs.
-
SwifterSwift
A handy collection of more than 500 native Swift extensions to boost your productivity. -
SwiftGen
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs! -
SwiftGen-Storyboard
The Swift code generator for your assets, storyboards, Localizable.strings, … — Get rid of all String-based APIs! -
SwiftLinkPreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images. -
Playbook
📘A library for isolated developing UI components and automatically taking snapshots of them. -
BetterSafariView
A better way to present a SFSafariViewController or start a ASWebAuthenticationSession in SwiftUI. -
SwiftPlantUML
A command-line tool and Swift Package for generating class diagrams powered by PlantUML -
Pythonic.swift
DISCONTINUED. Pythonic tool-belt for Swift – a Swift implementation of selected parts of Python standard library.
InfluxDB - Purpose built for real-time analytics at any scale.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Percentage or a related project?
README
Percentage
A percentage type for Swift
Makes percentages more readable and type-safe, for example, for APIs that currently accept a fraction Double
.
-.opacity(0.45)
+.opacity(45%)
Install
Add the following to Package.swift
:
.package(url: "https://github.com/sindresorhus/Percentage", from: "1.1.0")
Usage
See the [source](Sources/Percentage/Percentage.swift) for docs.
import Percentage
10% + 5.5%
//=> 15.5%
-10% / 2
//=> -5%
(40% + 93%) * 3
//=> 399%
50% * 50%
//=> 25%
30% > 25%
//=> true
50%.of(200)
//=> 100
Percentage(50)
//=> 50%
Percentage(fraction: 0.5)
//=> 50%
50%.fraction
//=> 0.5
10%.rawValue
//=> 10
print("\(1%)")
//=> "1%"
Percent.random(in: 10%...20%)
//=> "14.3%"
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.
Related
- Regex - Swifty regular expressions
- Defaults - Swifty and modern UserDefaults
- Preferences - Add a preferences window to your macOS app
- KeyboardShortcuts - Add user-customizable global keyboard shortcuts to your macOS app
- LaunchAtLogin - Add "Launch at Login" functionality to your macOS app
- More…