UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Should custom bindings be used for storing "real" data types?

Forums > 100 Days of SwiftUI

Reading about custom bindings in https://www.hackingwithswift.com/guide/ios-swiftui/2/2/key-points reminded me about how in the Tip project we have to store the tip amount in a var amount: String instead of var amount: Double because the TextField requires a string type.

With a custom binding, though, I imagine we could have a var amount: Double and cast the incoming string as a Double and cast the outgoing as a String and that way we can operate with the real Double data type instead of a string representation of it.

Is that a bad idea? Is that pattern used at all?

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.