DEV Community

Oluwasanmi Aderibigbe
Oluwasanmi Aderibigbe

Posted on

2 1

Day 62 of 100 Days Of SwiftUI

I just completed day 62 of 100 Days Of SwiftUI. Today I learnt about custom bindings and Actionsheet.

Custom bindings are useful when you need to perform side effects for example logging whenever your @State property changes.
For example, this is how you create a custom binding in SwiftUI:

struct ContentView: View {
    @State private var bidAmount: CGFloat = 0

    var body: some View {
        let bid = Binding<CGFloat>(
            get: {
                self.bidAmount
            },
            set: {
                self.bidAmount = $0
                print("New value is \(self.bidAmount)")
            }
        )

        return VStack {
            Text("Bid amount: \(bidAmount)")

            Slider(value: bid, in: 0...20)
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

This code creates a custom binding that sets the value of the bidAmount state property and also prints the value of bidAmount

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more