Post

Replies

Boosts

Views

Activity

Reply to SwiftUI Keyboard Toolbar not Displaying
Update after StackOverflow suggestion that did not resolve the issue: import SwiftUI @Observable class RootViewController: CustomStringConvertible { var description: String { return switch(currentView) { case .home: "Home" case .formView: "Form View" } } enum Views { case home case formView } public var currentView: Views = .home // This prevents the toolbar from displaying. Change to .formView, and it works. } struct ContentView: View { @State private var rootViewController = RootViewController() var body: some View { switch rootViewController.currentView { case .formView: FormView() case .home: HomeView() .environment(rootViewController) } } } struct FormView: View { @State private var text: String = "" @FocusState private var isInputActive: Bool var body: some View { NavigationStack { Form { TextField("Text", text: $text) .keyboardType(.decimalPad) .focused($isInputActive) Text("Text: \(text)") } .navigationTitle("Keyboard Toolbar Test") .toolbar { ToolbarItemGroup(placement: .keyboard) { Spacer() Button("Close") { isInputActive = false } } } .padding() } } } struct HomeView: View { @Environment(RootViewController.self) private var rootViewController var body: some View { Button("Open Form") { rootViewController.currentView = .formView } } } #Preview { ContentView() }
Topic: UI Frameworks SubTopic: SwiftUI
Oct ’25
Reply to SwiftUI Keyboard Toolbar not Displaying
Update after StackOverflow suggestion that did not resolve the issue: import SwiftUI @Observable class RootViewController: CustomStringConvertible { var description: String { return switch(currentView) { case .home: "Home" case .formView: "Form View" } } enum Views { case home case formView } public var currentView: Views = .home // This prevents the toolbar from displaying. Change to .formView, and it works. } struct ContentView: View { @State private var rootViewController = RootViewController() var body: some View { switch rootViewController.currentView { case .formView: FormView() case .home: HomeView() .environment(rootViewController) } } } struct FormView: View { @State private var text: String = "" @FocusState private var isInputActive: Bool var body: some View { NavigationStack { Form { TextField("Text", text: $text) .keyboardType(.decimalPad) .focused($isInputActive) Text("Text: \(text)") } .navigationTitle("Keyboard Toolbar Test") .toolbar { ToolbarItemGroup(placement: .keyboard) { Spacer() Button("Close") { isInputActive = false } } } .padding() } } } struct HomeView: View { @Environment(RootViewController.self) private var rootViewController var body: some View { Button("Open Form") { rootViewController.currentView = .formView } } } #Preview { ContentView() }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Oct ’25
Reply to SwiftData: Crash when deleting from model, but only in prod
What do you mean with "more verbose way"? It seems to be the same command but one is wrapped in a generic function. That's exactly what I mean. I'm deleting data from 5 different tables. The function call promotes code reuse so I don't have to declare the predicate 5 times, once for each table.
Replies
Boosts
Views
Activity
Oct ’25