Post

Replies

Boosts

Views

Activity

Reply to can't use @Environment for Binding?
I also had that problem, this is the solution: add @Bindable var viewModel = viewModel in your view’s body, even though I don’t think it is elegant. @Observable final class View1Model { var text: String = "" } struct View1: View { @State var viewModel = View1Model() var body: some View { View2() .environment(viewModel) } } struct View2: View { @Environment(View1Model.self) var viewModel var body: some View { // use @Bindable to get the binding @Bindable var viewModel = viewModel TextField("Text", text: $viewModel.text) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’23
Reply to [sample code]when model changed, the view in SwiftUI isn’t update
The solution is changing newLivingAccommodation.trip = trip to trip.livingAccommodation = newLivingAccommodation. After one year, Apple haven’t change this in their sample code.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’24
Reply to SwiftData preview sample code
on Xcode15 beta4, all workarounds above don’t work for me. I notice that release notes mentioned that it is a known issue and recommend to run on device replacing preview, but it is not convenient. is there any other workaround?
Replies
Boosts
Views
Activity
Jul ’23
Reply to Unable to Verify App: An internet connection is required to verify the trust of the developer' ... This app will not be available until verified.
I updated to iOS beta3 and Xcode15 beta3, the problem has solved.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’23
Reply to Unable to Verify App: An internet connection is required to verify the trust of the developer' ... This app will not be available until verified.
I have the same problem with my iPhone, but everything is ok on my iPad Pro, both are in the beta version OS, and in the same network. how strange!
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’23
Reply to can't use @Environment for Binding?
I also had that problem, this is the solution: add @Bindable var viewModel = viewModel in your view’s body, even though I don’t think it is elegant. @Observable final class View1Model { var text: String = "" } struct View1: View { @State var viewModel = View1Model() var body: some View { View2() .environment(viewModel) } } struct View2: View { @Environment(View1Model.self) var viewModel var body: some View { // use @Bindable to get the binding @Bindable var viewModel = viewModel TextField("Text", text: $viewModel.text) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’23