Post

Replies

Boosts

Views

Activity

Reply to can't use @Environment for Binding?
This code has good performance. But it is not cleaner than @EnvironmentObject struct View2: View { @Environment(View1Model.self) var viewModel var body: some View { TextField("Text", text: Binding(get: { viewModel.text }, set: { newValue in viewModel.text = newValue })) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to can't use @Environment for Binding?
struct TitleEditView: View { @Environment(Book.self) private var book var body: some View { @Bindable var book = book TextField("Title", text: $book.title) } } I found this from Bindable Document https://developer.apple.com/documentation/swiftui/bindable thanks @macrojd
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’23