swiftui

How can I unwrap an optional value inside a binding in Swift?

大憨熊 提交于 2020-11-24 12:08:40
问题 I'm building an app using SwiftUI and would like a way to convert a Binding<Value?> to a Binding<Value >. In my app I have an AvatarView which knows how to render an image for a particular user. struct AvatarView: View { @Binding var userData: UserData ... } My app holds a ContentView that owns two bindings: a dictionary of users by id, and the id of the user whose avatar we should be showing. struct ContentView: View { @State var userById: Dictionary<Int, UserData> @State var activeUserId: