Provide views, controls, and layout structures for declaring your app's user interface using SwiftUI.

SwiftUI Documentation

Posts under SwiftUI subtopic

Post

Replies

Boosts

Views

Activity

Popover in Toolbar Causes Crash in Catalyst App on macOS 26
Hi everyone, I’ve encountered an issue where using a popover inside the toolbar of a Catalyst app causes a crash on macOS 26 beta 5 with Xcode 26 beta 5. Here’s a simplified code snippet: import SwiftUI struct ContentView: View { @State private var isPresentingPopover = false var body: some View { NavigationStack { VStack { } .padding() .toolbar { ToolbarItem { Button(action: { isPresentingPopover.toggle() }) { Image(systemName: "bubble") } .popover(isPresented: $isPresentingPopover) { Text("Hello") .font(.largeTitle) .padding() } } } } } } Steps to reproduce: Create a new iOS app using Xcode 26 beta 5. Enable Mac Catalyst (Match iPad). Add the above code to show a Popover from a toolbar button. Run the app on macOS 26, then click the toolbar button. The app crashes immediately upon clicking the toolbar button. Has anyone else run into this? Any workarounds or suggestions would be appreciated! Thanks!
1
0
62
Aug ’25
watchOS 26 system clock collision
Our app has an infrequently used but useful calculator screen similar to Apple's calculator app where the current value ticker squats in the top toolbar trailing area, extending into the system clock area. In 26 beta, that view is now broken: the system clock not longer hides when a layout collision is detected. Can the prior avoidance behavior (or an API to hide the clock) be triggered somehow?
2
0
51
Aug ’25
Dividers not appearing in menu bar on iPadOS 26
On macOS 26 I can see the dividers when I open my Help menu: However, on iPadOS 26 the dividers don't appear: I am simply using Divider() to separate my menu bar items in my CommandGroup. iPadOS does support dividers as I can see them for the system generated Edit menu but for some reason it's not working here. Does anyone know if I am doing something wrong with the iPadOS implementation?
2
1
74
Aug ’25
`.task(id:_:)` starting in the `Task.isCancelled` state
I'm running into a weird SwiftUI concurrency issue that only seems to happen on a real device (iOS 18.5 in my case), and not in simulator. I have a NavigationSplitView where the Detail view uses .task(id:_:) to perform some async work upon appearance (in my real-world case, a map snapshot). When running this on a real device, the first execution of the task works as expected. However, any task subsequent executions, even ones for the same id, always start in the Task.isCancelled state. Is there something about .task(id:_:) that I'm misunderstanding, or have I stumbled upon a serious bug here? import SwiftUI struct ContentView: View { var body: some View { TaskBugSplitView() } } struct TestItem: Identifiable, Hashable { var id: Int var name: String } struct TaskBugSplitView: View { @State private var selectedItemIndex: [TestItem].Index? @State private var testItems: [TestItem] = [ TestItem(id: 1, name: "First Item"), TestItem(id: 2, name: "Second Item"), TestItem(id: 3, name: "Third Item"), TestItem(id: 4, name: "Fourth Item"), TestItem(id: 5, name: "Fifth Item") ] var body: some View { NavigationSplitView { List(testItems.indices, id: \.self, selection: $selectedItemIndex) { item in Text(testItems[item].name) } } detail: { if let selectedItemIndex { TaskBugDetailView(item: testItems[selectedItemIndex]) } else { Text("Select an item") .foregroundStyle(.secondary) } } } } struct TaskBugDetailView: View { @State var item: TestItem @State private var taskResult = "Not started" var body: some View { VStack(spacing: 20) { Text("Item: \(item.name)") .font(.title2) Text("Task Result:") .font(.headline) Text(taskResult) .foregroundStyle(taskResult.contains("CANCELLED") ? .red : .primary) Spacer() } .padding() .navigationTitle(item.name) .task(id: item.id) { // BUG: On real devices, Task.isCancelled is true immediately for all tasks // after the first successful one, even though the ID has changed if Task.isCancelled { taskResult = "CANCELLED at start" print("Task cancelled at start for item \(item.id)") return } taskResult = "SUCCESS" print("Task completed successfully for item \(item.id)") } } }
2
0
63
Aug ’25
Should I use tabview or navigationsplitview?
I want to make an app that has a navigationsplitview with three columns on iPad but a tapbar on iPhone and small iPad windows. How should I do that? Since iOS 18 you can use tabview to make a tabbar on iPhone and a sidebar on iPad, but then you just have two columns. Is there a way to make this possible? Can you make a navigationsplitview sidebar move into a tabbar? And how did you do it before iOS 18 like in the podcasts app?
Topic: UI Frameworks SubTopic: SwiftUI
0
0
66
Aug ’25
Unexpected lines appear in PDFView on visionOS 26 beta
I’m attempting to display a PDF file in a visionOS application using the PDFView in PDFKit. When running on device with visionOS 26, a horizontal solid line appears on some pages, while on other pages, both a horizontal and vertical solid line appear. These lines do not appear in Xcode preview canvas (macOS, visionOS) on device running visionOS 2.5 on Mac running macOS 15.6 I thought that this could possibly be the page breaks, but setting displaysPageBreaks = false did not appear to be effective. Are there any other settings that could be causing the lines to display? Code Example struct ContentView: View { @State var pdf: PDFDocument? = nil var body: some View { PDFViewWrapper(pdf: pdf) .padding() } } #Preview(windowStyle: .automatic) { ContentView(pdf: PDFDocument(url: Bundle.main.url(forResource: "SampleApple", withExtension: "pdf")!)) .environment(AppModel()) } struct PDFViewWrapper: UIViewRepresentable { let pdf: PDFDocument? func makeUIView(context: Context) -> PDFView { let view = PDFView() view.document = pdf view.displaysPageBreaks = false return view } func updateUIView(_ uiView: PDFView, context: Context) { uiView.document = pdf } } Tested with Xcode Version 16.4 (16F6) Xcode Version 26.0 beta 5 (17A5295f) visionOS 2.5 visionOS 26 Beta 5 I
2
0
62
Aug ’25
`onTapGesture` not triggered on `Map` views
When building with iOS 26 SDK beta 5 (23A5308f), onTapGesture is no longer being triggered on Map views. This appears to be a regression in beta 5 specifically, as this issue was not present in beta 4. How to reproduce Code The following code demonstrates the issue, as seen in the videos below. import MapKit import SwiftUI struct ContentView: View { @State private var location = CGPoint.zero var body: some View { Map() .onTapGesture { location in self.location = location } .safeAreaInset(edge: .bottom) { VStack(alignment: .center) { Text("iOS \(UIDevice.current.systemVersion)") .font(.largeTitle) Text("Tapped Location") Text("\(location.x), \(location.y)") } .frame(maxWidth: .infinity, alignment: .center) .background(.background) } } } Demo The gifs below show the behavior in iOS 18.5 (in which the tap gestures are recognized and tapped coordinate is displayed in the safe area inset) and iOS 26 beta 5 (in which the tap gestures have no effect): iOS 18 iOS 26 Next steps? Is there a recommended workaround for this issue?
16
3
329
Aug ’25
Control Widget SF image cannot stably display
I'm working on the control widget which should display the SF image on the UI, but I have found that it cannot be displayed stably. I have eight CarCtrlWidgets which is about the type doorLock、chargeCover、frontBox、 locateCarLight、 locateCarHorn、 ventilate、 backBox and airCondition, it should all be showed but sometime they only show the text and placeholder. I'm aware of the images should be custom SF image and I can see them to show perfectly sometimes, but in other time it is just failed. This's really confused me, can anyone help me out? deviceversion 18.5;device model iPhone 16 pro;
0
1
37
Aug ’25
Tabs Hiding ToolBarTitleMenu on iPad...
Anyone run into this situation? I am using a TabView for iOS App and also decided to use a ToolbarTitleMenu on a couple of the Main views. Everything works as expected on iPhone versions of the App because the tabs are displayed along the bottom. However on iPad they are "floating" in the top middle of the screen and therefore completely obscure the ToolBarTitleMenu selector. Is there a way to get around this? I am surprised that Apple would have a standard control that does not work well on these two devices. Of course I can do a compiler #IF but would like to know if there is something I am missing here.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
55
Aug ’25
Unexpected shape around a GlassProminentButtonStyle button with safeAreaBar in NavigationStack
I’m trying to use the new safeAreaBar() to place a button in the bottom safe area of the view for the main action. However, there’s a bug when the view is inside a NavigationStack: a white or translucent background appears around the button. When I move the view outside of the NavigationStack, the issue goes away. NavigationStack { List { Text("ok") } .safeAreaBar(edge: .bottom) { Button(action: {}, label: { Text("Continue").font(.headline) }) .buttonStyle(.glassProminent) } } Is it a known issue?
2
0
77
Aug ’25
Possible iOS 26 bug: tabViewBottomAccessory not affected by toolbarVisibility
I'm working with an app that has a structure of a main TabView, where each Tab has its own NavigationStack. A very simplified rendition of the app looks like this: struct ContentView: View { var body: some View { TabView { Tab("Tab 1", systemImage: "document") { NavigationStack { VStack { Text("Tab 1") NavigationLink("Load Detail") { VStack { Text("Detail View") }.toolbarVisibility(.hidden, for: .bottomBar, .tabBar) } } } } Tab("Tab 2", systemImage: "map") { NavigationStack { VStack { Text("Tab 2") } } } }.tabViewBottomAccessory { Button("Action") {} } } } With this structure, when I load the detail view in the NavigationLink, I see the tab bar hidden as I would expect. Unfortunately, the tabViewBottomAccessory button remains visible. I've taken some steps to try and fix this ( injecting state at different levels that observe the navigation path and try to change the visibility ) but none of those attempts work, and it seems to me that fundamentally, if the tab bar is desired to be hidden, then so also should the tab accessory be hidden. I didn't find anywhere online that seemed to indicate this was a known bug, so wanted to post this here first to see if this was the behavior that is expected, or worth filing a bug in iOS 26.
1
0
81
Aug ’25
Liquid Glass clear variant isn't clear
I've been experimenting with Liquid Glass quite a bit and watched all the WWDC videos. I'm trying to create a glassy segmented picker, like the one used in Camera: however, it seems that no matter what I do there's no way to recreate a truly clear (passthrough) bubble that just warps the light underneath around the edges. Both Glass.regular and Glass.clear seem to add a blur that can not be evaded, which is counter to what clear ought to mean. Here are my results: I've used SwiftUI for my experiment but I went through the UIKit APIs and there doesn't seem to be anything that suggests full transparency. Here is my test SwiftUI code: struct GlassPicker: View { @State private var selected: Int? var body: some View { ScrollView([.horizontal], showsIndicators: false) { HStack(spacing: 0) { ForEach(0..<20) { i in Text("Row \(i)") .id(i) .padding() } } .scrollTargetLayout() } .contentMargins(.horizontal, 161) .scrollTargetBehavior(.viewAligned) .scrollPosition(id: $selected, anchor: .center) .background(.foreground.opacity(0.2)) .clipShape(.capsule) .overlay { DefaultGlassEffectShape() .fill(.clear) // Removes a semi-transparent foreground fill .frame(width: 110, height: 50) .glassEffect(.clear) } } } Is there any way to achieve the above result or does Apple not trust us devs with more granular control over these liquid glass elements?
2
3
94
Aug ’25
iPadOS 26 Menu Bar - Hiding Unused Menu Items
How to Hide Unused Menu Items on iPadOS Menu Bar in SwiftUI? (Xcode 26 beta 4, iPadOS 26 beta 4) We’re working on adding menu bar support to our SwiftUI app on iPadOS, aiming to provide a more consistent and productive experience across platforms. We’d like to hide system-provided menu items that aren’t relevant to our app, such as: Open… Select All Customize Toolbar… New Window, Show All Windows, Open Windows, etc. Is there a way to control which default items appear in the menu bar? Feedback ID: FB18792279
0
0
87
Aug ’25
iPadOS 26 Menu Bar - Undo / Redo
How to Enable or Customize Undo/Redo Menu Items on iPadOS Menu Bar in SwiftUI? (Xcode 26 beta 4, iPadOS 26 beta 4) We’re working on adding menu bar support to our SwiftUI app on iPadOS, aiming to provide a more consistent and productive experience across platforms. Our app is a unified iPad/macOS app that uses UndoManager to support undo/redo operations. However, we’ve run into the following issues: On macOS, undo and redo work as expected via the menu bar. On iPadOS, the Undo and Redo menu items are always disabled, even though the functionality works within the app. We also explored the possibility of hiding the system-generated Undo/Redo menu items so we could provide custom implementations—but couldn’t find a way to remove or override them. Question: Is there a recommended approach to enable or customize the Undo/Redo menu bar items on iPadOS using SwiftUI? Any suggestions or insights would be greatly appreciated! Feedback ID: FB18792279
0
1
56
Aug ’25
iPadOS 26 Menu Bar - Copy / Paste
How to Support Menu Bar Copy/Paste/Cut/Delete Commands on iPadOS with SwiftUI? (Xcode 26 beta 4, iPadOS 26 beta 4) We’re working on adding menu bar support to our SwiftUI app on iPadOS, aiming to provide a more consistent and productive experience across platforms. However, we’ve encountered a challenge when trying to handle standard editing commands like Copy, Cut, Paste, and Delete from the menu bar: On iPadOS, SwiftUI modifiers such as onCopyCommand, onCutCommand, onPasteCommand, and onDeleteCommand appear to be unavailable. Additionally, since we can’t hide or override the default app menus, we’re unsure how to hook into or replace their behavior effectively. Question: What’s the recommended way to support standard editing actions like copy/paste via the menu bar in SwiftUI on iPadOS? Are there any workarounds or APIs we might have overlooked? Any guidance or best practices would be greatly appreciated! Feedback ID: FB18792279
1
0
66
Aug ’25
NavigationSplitView content column renders list in plain style – even on iPhone
Hi everyone, I’m building an iOS app that originally targeted iPhone using NavigationStack. Now I’m adapting it for iPad and switched to using NavigationSplitView to support a three-column layout. The structure looks like this: NavigationSplitView { A // Sidebar } content: { B // Middle column – this shows a list } detail: { C // Detail view } The issue is with the list shown in view B (the content column). It appears completely unstyled, as if it’s using .listStyle(.plain) — with no background material, and a very flat look. I can understand that this might be intentional on iPad to visually distinguish the three columns. However, the problem is that this same unstyled list also appears on iPhone, even though iPhone only shows a single column view at a time! I tried explicitly setting .listStyle(.insetGrouped) or .listStyle(.grouped) on the list in view B, but it makes no difference. When I go back to NavigationStack, the list in B is styled properly, just as expected — but then I lose the enhanced iPad layout. What I’m looking for: I’d like to keep using NavigationSplitView, but I want the list in the content column (view B) to use the default iOS list styling, at least on iPhone. Is there any way to achieve this? Thanks!
0
0
47
Aug ’25
NavigationSplitView content column renders list in plain style – even on iPhone
Hi everyone, I’m building an iOS app that originally targeted iPhone using NavigationStack. Now I’m adapting it for iPad and switched to using NavigationSplitView to support a three-column layout. The structure looks like this: NavigationSplitView { A // Sidebar } content: { B // Middle column – this shows a list } detail: { C // Detail view } The issue is with the list shown in view B (the content column). It appears completely unstyled, as if it’s using .listStyle(.plain) — with no background material, no grouped sections, and a very flat look. I can understand that this might be intentional on iPad to visually distinguish the three columns. However, the problem is that this same unstyled list also appears on iPhone, even though iPhone only shows a single column view at a time! I tried explicitly setting .listStyle(.insetGrouped) or .listStyle(.grouped) on the list in view B, but it makes no difference. When I go back to NavigationStack, the list in B is styled properly, just as expected — but then I lose the enhanced iPad layout. What I’m looking for: I’d like to keep using NavigationSplitView, but I want the list in the content column (view B) to use the default iOS list styling, at least on iPhone. Is there any way to achieve this? Thanks!
0
0
34
Aug ’25
How is the transition effect in Apple’s Calendar app built (month → day view)?
Hi everyone, I’m trying to recreate the beautiful transition effect used in Apple’s built-in Calendar app — specifically the one where, when you tap on a month, you’re “pulled into” the next view, and when going from month to day, the views seem to slide vertically, almost as if one is pushing the other off-screen. It’s not the standard right-to-left slide you get with NavigationStack or NavigationLink, and it feels much more immersive and dynamic. I’ve been experimenting with .matchedGeometryEffect and .transition(.move(...)) in a ZStack, and while I can replicate some aspects, I’m still missing that fluid, directional pull that makes it feel like you’re diving deeper into the calendar. I’m also unsure how much the view structure between the source and destination needs to match for the matchedGeometryEffect to really shine. Does anyone know what APIs or techniques Apple might be using internally to build that kind of animation? Is there a clean way to achieve something similar using SwiftUI as of iOS 17 or 18? Would love to hear if someone here has successfully replicated this or has tips on best practices. Thanks in advance!
Topic: UI Frameworks SubTopic: SwiftUI
0
0
25
Aug ’25