Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lawrencebensaid/blissfulbinding

Make you SwiftUI coding experience more joyful with an extended Binding class
https://github.com/lawrencebensaid/blissfulbinding

Last synced: 16 days ago
JSON representation

Make you SwiftUI coding experience more joyful with an extended Binding class

Awesome Lists containing this project

README

        

# BlissfulBinding

SwiftUI provides a Binding class, which can sometimes be hard to work with when you are dealing with optionals.
BlissfulBinding extends SwiftUI's Binding class with some features allowing you to work with these optionals more easily:.

### Introducing the Coalescing Operator `??`
A familiar operator to Swift. BlissfulBinding allows you to use this operator with SwiftUI's Binding.
This is useful because a lot of SwiftUI modifiers expect unwrapped variables.

```swift
import BlissfulBinding

struct MyView: View {

@Binding var present: Bool?

var body: some View {
Text("Hello, World!")
.sheet(isPresented: $present ?? false) {
Text("Hi!")
}
}

}
```

### Introducing .notNil function
This allows you to convert an Optional Binding variable to a Boolean Binding variable.

```swift
import BlissfulBinding

struct MyView: View {

@Binding var message: String?

var body: some View {
Text("Hello, World!")
.sheet(isPresented: .notNil($message)) {
Text(message ?? "")
}
}

}
```