Swiftpack.co - benlmyers/better-binding as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by benlmyers.
benlmyers/better-binding 1.1.4
A small SwiftUI extension that improves Binding operators.
⭐️ 0
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/benlmyers/better-binding.git", from: "1.1.4")

BetterBinding

BetterBinding aims to improve SwiftUI's Binding by introducing several operators that will save you time when writing SwiftUI views.

Installation

BetterBinding can be installed via Swift Package Manager:

https://github.com/benlmyers/better-binding

Usage

BetterBinding has 5 binding-related operators you can use to make using Binding in your projects much quicker.

Quick Constant

Define a constant using the % operator:

%false // .constant(false)
%variable // .constant(variable)
%(-2.0) // .constant(-2.0)

Quick Unwrap

Unwrap a binding using the % operator:

%myBindingVar // myBindingVar.wrappedValue

Conditional Unwrap

Unwrap Binding<Optional<T>> values conditionally:

$myBindingOptionalValue ?? %true

Force Unwrap

Unwrap Binding<Optional<T>> values forcefully:

!$myBindingOptionalValue

Binding and Non-Binding Equality

Check the equality of a Binding<T>'s unwrapped value with a T value, and get a Binding<Bool> source of truth:

Toggle("Option 0", isOn: $optionValue == 0)
Toggle("Option 1", isOn: $optionValue == 1)
Toggle("Option 2", isOn: $optionValue != 2)

Logical Operators

Use binary locical operators to unify two Binding<Bool>s:

Toggle("A or B", isOn: $valueA || $valueB) // Toggling this will set both to the new value.
Toggle("A and B", isOn: $valueA && $valueB) // Toggling this will set both to the new value.

Negate a Binding<Bool>:

Toggle("Not A", isOn: !$valueA)

GitHub

link
Stars: 0
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.1.4
2 weeks ago

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