Post

Replies

Boosts

Views

Activity

Broken NavigationLink behavior when using @StateObject and a ForEach inside a Form
I'm having this strange issue when I use @StateObject + ForEach and NavigationLink Inside a Form. This breaks bindings in the child view shown. Consider the following ViewModel class with one published property to use from a View: final class ViewModel: ObservableObject { @Published var isActive = false } When using this view: struct MainView: View { @StateObject var viewModel = ViewModel() var body: some View { NavigationView { Form { NavigationLink ( destination: ChildView(isActive: $viewModel.isActive), isActive: $viewModel.isActive, label: { Text("Go to child view") } ) /* Adding this ForEach causes the NavigationLink above to have a broken binding */ ForEach(1..4) { Text("\($0)") } } .navigationBarTitle("Test") } } } And this SubView: struct ChildView: View { @Binding var isActive: Bool var body: some View { Button("Go back", action: { isActive = false }) } } The Issue The expected result is when tapping on "Go to child view", navigating to the subview and tapping "Go back" to return to the main view - it should navigate back using the isActive binding. But actually, the button "Go Back" Doesn't work. BUT! If I remove the ForEach element from the form in the main view, the button works again. And it looks like the ForEach breaks everything. Additional findings: Changing Form to VStack fixes the issue Using a struct and a @State also fixes the issue Extracting the ForEach to a subview fixes the issue but as soon as I pass the viewmodel or part of it to the subview as a binding or as an ObservedObject - it still broken Can anything advise if there is a logical issue with the code or is it a SwiftUI bug? Any suggestions for a workaround?
2
0
1.9k
Feb ’21
Crash on launch when adding a Swift package with a binary target
I have compiled Google's WebRTC library and bundled up everything into xcframework in order to distribute as a binary framework in Swift package manager. When I add the package to my project it compiles and runs on a simulator. However, on a physical device, it crashes on launch with the following error: dyld: Library not loaded: @rpath/WebRTC.framework/WebRTC Referenced from: /private/var/containers/Bundle/Application/AA9F8C9C-7EF4-4556-8848-1EEFE1785658/WebRTC-Demo.app/WebRTC-Demo Reason: image not found dyld: launch, loading dependent libraries DYLDLIBRARYPATH=/usr/lib/system/introspection DYLDINSERTLIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib Further investigation: After archiving the project and exporting ipa file, the ipa file is missing the binary framework and still crashing on launch. Removing the Swift package and attaching the xcframework manually (by drag and drop) works on Simulators and physical devices. Tech specs XCFramework created on macOS 10.15.5 with Xcode 11.5 Used Xcode 12.0 beta 1 on macOS 10.15 for the app which uses the framework. I got the error above on iPhone X and iPad pro 10.5" Used the following Package.swift - https://github.com/stasel/WebRTC-iOS/blob/xcode-12/Package.swift file. Framework download link can be found in the Package.Swift file above. Any suggestions/insights would be helpful. Thanks!
17
0
18k
Jul ’20