iOS14 introducing errors with @State bindings

It looks like in iOS 14 the sheet(isPresented:content:) is now created beforehand, so any changes made to selectedModel are ignored. Try using sheet(item:content:) instead: var body: some View { List { … } .sheet(item: self.$selectedModel) { SpeakerDetailView(speaker: $0) } } and dismiss the sheet using @Environment(\.presentationMode): struct SpeakerDetailView: View { @Environment(\.presentationMode) private var presentationMode var … Read more

iOS 14 SwiftUI Keyboard lifts view automatically

For .ignoresSafeArea to work you need to fill all the available area (eg. by using a Spacer). The following will not work (no Spacers, just a TextField): struct ContentView: View { @State var text: String = “” var body: some View { VStack { TextField(“asd”, text: self.$text) .textFieldStyle(RoundedBorderTextFieldStyle()) } .ignoresSafeArea(.keyboard, edges: .bottom) } } However, … Read more

Share data between main App and Widget in SwiftUI for iOS 14

You can add the AppGroup capability for both your Widget and App (here is a very good explanation how to add it). UserDefaults Instead of UserDefaults.standard just use the shared UserDefaults for your AppGroup: UserDefaults(suiteName: <your_app_group>) Then you can read/write data like explained in this answer. File Container With the AppGroup entitlement you get access … Read more

SwiftUI iOS14 – NavigationView + List – Won’t fill space

Problem It looks like the default styles of a List or NavigationView in iOS 14 may in some cases be different than in iOS 13. Solution #1 – explicit listStyle It’s no longer always the PlainListStyle (as in iOS 13) but sometimes the InsetGroupedListStyle as well. You need to explicitly specify the listStyle to PlainListStyle: … Read more