I wrote an app in SwiftUI last year and it's on the App Store. I am working on it in XCode 12 for iOS 14. When I pass a string to a View in .sheet, the String won't get passed. It worked in SwiftUI 1.0, but now doesn't in SwiftUI 2.0. I tested this by printing the variable right before passing to the view and it shows but doesn't print when the new view is opened in .sheet.
Anyone having this issue?
Running XCode 12 Beta 6 & iOS 14 Beta 7
Anyone having this issue?
Running XCode 12 Beta 6 & iOS 14 Beta 7
Thanks for showing your code.Ok, here's the code.
As far as tried, @State variables used in a closure for sheet method do not work in some occasions which are hard to predict.
In my opinion, it definitely is a bug, but not sure if Apple will fix it soon.I'm wondering if it's a bug with SwiftUI.
Anyway, you should better send a feedback to Apple.
One workaround, pass a Binding instead of a value of @State variables.
Code Block .sheet(isPresented: self.$showingShipEditor) { ShipEditingView(shipName: self.$shipSelected) //<- Please do not miss `$` }
Code Block struct ShipEditingView: View { @Binding var shipName: String //<- Put `@Binding` here //... }