How to unwrap Binding with Optional in SwiftUI
Issue #677
The quick way to add new properties without breaking current saved Codable is to declare them as optional. For example if you use EasyStash library to save and load Codable models.
1 | import SwiftUI |
This new property when using dollar syntax $input.notificationId
turn into Binding with optional Binding<Strting?>
which is incompatible in SwiftUI when we use Binding.
1 | struct MaterialTextField: View { |
The solution here is write an extension that converts Binding<String?>
to Binding<String>
1 | extension Binding where Value == String? { |
so we can use them as normal
1 | MaterialTextField(text: $input.notificationId.toNonOptional()) |