There is workaround how to avoid crash
var nameBinding: Binding<String>? {
guard let name = viewModel.name else { return nil }
return Binding {
name
} set: { value in
viewModel.name = value
}
}
...
if let name = nameBinding {
ChildView(selectedName: name)
}
...
Here is some other suggestions
https://stackoverflow.com/questions/76241232/binding-with-optional-value-causes-runtime-crash/76243321#76243321
this issue can also be produced without @Environment https://stackoverflow.com/questions/75007473/swiftui-picker-with-style-navigationlink-causes-100-cpu-usage
There is workaround how to avoid crash
var nameBinding: Binding<String>? {
guard let name = viewModel.name else { return nil }
return Binding {
name
} set: { value in
viewModel.name = value
}
}
...
if let name = nameBinding {
ChildView(selectedName: name)
}
...
Here is some other suggestions
https://stackoverflow.com/questions/76241232/binding-with-optional-value-causes-runtime-crash/76243321#76243321
this issue can also be produced without @Environment https://stackoverflow.com/questions/75007473/swiftui-picker-with-style-navigationlink-causes-100-cpu-usage