A better way to create SwiftUI bindings

Episode Clip • Jul 30, 2024

If you have ever created a binding using the get:set: initializer, you may want to reconsider. Bindings created with this initializer are difficult for SwiftUI to properly track because there is no identifying information associated with them since closures are not Hashable in Swift. Luckily there is a way to derive bindings that provide identifying information to SwiftUI by using @dynamicMemberLookup and subscripts.

This is an excerpt from our episode Modern UIKit: UIControl Bindings.

Get started with our free plan

Our free plan includes 1 subscriber-only episode of your choice, access to 64 free episodes with transcripts and code samples, and weekly updates from our newsletter.

View plans and pricing