We can add ornaments to popovers shown by PresentationComponent, but I’m not sure if we should.
While working on the editor for entities in a Volume-based app, I had the idea to add ornaments to the presented views. The entire app exists inside a volume. A user can tap a item to present a popoverUI to edit it. This is displayed using the new PresentationComponent in visionOS 26.
Ornaments have a new attachment anchor option this year: .parent().
.ornament(attachmentAnchor: .parent(.top), ornament: {...})
This works well in the Simulator. We can add ornaments around this popover view just like we would with a window.
Unfortunately, when I run this on device I get a different experience. Any part of the ornament that overlaps with the popover content isn’t rendered correctly. Sometimes it entirely disappears, other times it becomes partially transparent.
We could use content alignment to try to make sure the ornament doesn’t overlap the popover content.
.ornament(attachmentAnchor: .parent(.top), contentAlignment: .bottom, ornament: {...})
This works sometimes–but not all the time. It’s not clear if this is a bug or not, because I’m not sure if we are even supposed to be able to use ornaments in this way. Here is my hierarchy:
An app opens as a Volume
Volume presenting a RealityView, with its own ornament using .scene() anchor
Multiple Entities with Presentation Component show an edit view
The view uses .parent() anchor to add ornaments.
What makes me unsure is that other methods for drawing UI in RealityView don’t seem to work with ornaments. For example, if I add an attachment to show a view with the ornament–even when I use the .parent() anchor–the ornament is anchor to the volume, not the attachment view.
So what do we think? Is this a rendering bug? Are ornaments intended to work with attachments and presentations?
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Posts under SwiftUI tag
200 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Recently I've been working on a demo project called iLibrary. The main goal was to learn more about CloudKit and SwiftData. After a while I noticed that there were some hangs/freezes when running the app in debug mode.
I first tried this with Xcode 15.4 and iOS 17.5. Here the hang only appears at the beginning, but only for a few seconds. But when I exit debug mode, there are no more hangs.
With Xcode 16 beta 4 and iOS 18 it looks completely different. In this case, the hangs and freezes are always present, whether in debug mode or not. And it's not just at the beginning, it's throughout the app. I'm aware that this is still a beta, but I still find this weird. And when I profile this I see that the main thread gets quite overloaded. Interestingly, my app doesn't have that many operations going on. So I guess something with the sync of SwiftData or my CloudKitManger where I fetch some records from the public database is not running fine.
Lastly, I wanted to delete the iCloud app data. So I went to Settings and tried to delete it, but it didn't work. Is this normal?
Does anyone have any idea what this could be? Or has anyone encountered this problem as well? I'd appreciate any support.
My project: https://github.com/romanindermuehle/iLibrary
I've been exploring the resources from WWDC25 Session 280: "Code-along: Cook up a rich text experience in SwiftUI with AttributedString" and the SwiftUI documentation on "Building rich SwiftUI text experiences." After spending some time experimenting and trying to implement these features with these APIs on iOS26 , I’ve run into a specific question.
Is there a way to programmatically trigger the Format Sheet directly—for example, from a custom button—rather than requiring the user to go through the multi-step process of selecting text, opening the context menu, tapping "Format," and then selecting "More"?
I’d like to provide a more streamlined editing experience in my app. Any guidance would be greatly appreciated!
In my SwiftUI iOS app, I need to detect which key (and modifier flags – Command, Option, Shift, Control) a user presses, but I don't want to pre-register them using .keyboardShortcut(_:modifiers:).
My use case is that keyboard shortcuts are user-configurable, so I need to capture the actual key + modifier combination dynamically at runtime and perform the appropriate action based on the user’s settings.
Questions:
What is the recommended way to detect arbitrary key + modifier combinations in SwiftUI on iOS?
Is there a SwiftUI-native solution for this, or should I rely on UIPressesEvent and wrap it with UIViewControllerRepresentable?
If UIKit bridging is necessary, what is the cleanest pattern for integrating this with SwiftUI views (e.g., Buttons)?
Any official guidance or best practices would be greatly appreciated!
I'm writing an iOS app that shares content with buddies. So my app will run in one language but the shared content will use the locale configured for the buddy.
I found this Apple documentation which suggests that locale: (Locale(identifier: is the solution.
Apple Documentation
But I can't get it to work.
Here's sample code.
struct LocalizationDemoView: View {
@State var isEnglish = true
var body: some View {
var myLocale: String { isEnglish ? "en": "de" }
VStack {
Toggle("Switch language", isOn: $isEnglish).frame(maxWidth: 200)
HStack {
Text("\(myLocale): ")
Text(String(localized: "Hello world!", locale: (Locale(identifier: myLocale)), comment: "To share"))
}
}
}
}
And here's the excerpt from the string catalog:
{
"sourceLanguage" : "en",
"strings" : {
"Hello world!" : {
"comment" : "To share",
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "🇩🇪 Moin Welt!"
}
},
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "🇬🇧 Hello world!"
}
}
}
}
}
}
Has Apple reduced support for string catalogs or is my code wrong?
Xcode 16.4 compiled on MacOS 15.6.1, device iOS 18.6.2
For a number of complex views in my app, I need to embed scrollable objects (like List, Form or TextEditor) in a ScrollView. To do that, I need to apply a limit to the height of the embedded object.
What I would like to do is set that limit to the actual height of the content being displayed in the List, Form, TextEditor, etc. (Note that this height calculation should be dynamic, so that content changes are properly displayed.
I attempted the following:
@State listHeight: CGFloat = .zero
List {
... content here
}
.onScrollGeometryChange(for: CGFloat.self, of: { geometry in
return geometry.contentSize.height
}, action: { oldValue, newValue in
if oldValue != newValue {
listHeight = newValue
}
})
.frame(height: listHeight)
.scrollDisabled(true)
This does not work because geometry.contentSize.height is always 0. So it is apparent that .onScrollGeometryChangedoes not interact with the internal scrolling mechanism of List. (Note, however, that.scrollDisabled` does work.)
Does anyone have a suggestion on how I might get this to work?
At WWDC the scroll edge effect was presented as a variable blur combined with a soft gradient.
Since beta 4 the bottom scroll edge effect has no blur, the top bar sometimes has, but sometimes does not. Even in my own app I have two views with totally different results. This was not changed back in beta 5, so I assume this is not a bug but an intended change.
It's hard to design for such a moving target. Especially the missing bottom blur looks bad in a lot of places in my app and I'm debating not shipping the new design if this does not get resolved.
Is there any guidance how this effect is supposed to look now? At this point it just seems random and there's no way adjust the way it looks.
Phone: Top blur, bottom no blur
Settings: Top blur, bottom no blur
Notes: No blur at all
Music: No blur at all
My own app: No top blur
My own app: Top blur
Hello,
It's impossible to manage hit area for textfield and it's already too small by default (detected with Accessibility Inspector).
I'm tried to force with modifier "frame(minHeight: xxx)", the component change the height but the hit area is still in same size.
Have to tips to fix this issue?
I'm building a visionOS app where users can place canvases into the 3D environment. These canvases are RealityKit entities that render web content using a WKWebView. The web view is regularly snapshotted, and its image is applied as a texture on the canvas surface.
When the user taps on a canvas, a WindowGroup is opened that displays the same shared WKWebView instance. This works great: both the canvas in 3D and the WindowGroup reflect the same live web content.
The canvas owns the WKWebView and keeps a strong reference to it.
Problem:
Once the user closes the WindowGroup, the 3D canvas stops receiving snapshot updates. The snapshot loop task is still running (verified via logs), but WKWebView.takeSnapshot(...) never returns — the continuation hangs forever. No error is thrown, no image is returned.
If the user taps the canvas again (reopening the window), snapshots resume and everything works again.
@MainActor
private func getSnapshot() async -> UIImage? {
guard !webView.isLoading else { return nil }
let config = WKSnapshotConfiguration()
config.rect = webView.bounds
config.afterScreenUpdates = true
return await withCheckedContinuation { continuation in
webView.takeSnapshot(with: config) { image, _ in
continuation.resume(returning: image)
}
}
}
What I’ve already verified:
The WKWebView is still in memory.
The snapshot loop (Task) is still running; it just gets stuck inside takeSnapshot(...).
I tried keeping the WKWebView inside a hidden UIWindow (with .alpha = 0.01, .windowLevel = .alert + 1, and isHidden = false).
Suspicion
It seems that once a WKWebView is passed into SwiftUI and rendered (e.g., via UIViewRepresentable), SwiftUI takes full control over its lifecycle. SwiftUI tells WebKit "This view got closed" and WebKit reacts by stopping the WKWebView. Even though it still exists in memory and is being hold by a strong reference to it in the Canvas-Entity.
Right now, this feels like a one-way path:
Starting from the canvas, tapping it to open the WindowGroup works fine.
But once the WindowGroup is closed, the WebView freezes, and snapshots stop until the view is reopened.
Questions
Is there any way under visionOS to:
Keep a WKWebView rendering after its SwiftUI view (WindowGroup) is dismissed?
Prevent WebKit from suspending or freezing the view?
Embed the view in a persistent system-rendered context to keep snapshotting functional?
For context, here's the relevant SwiftUI setup
struct MyWebView: View {
var body: some View {
if let webView = WebViewManager.shared.getWebView() {
WebViewContainer(webView: webView)
}
}
}
struct WebViewContainer: UIViewRepresentable {
let webView: WKWebView
func makeUIView(context: Context) -> UIView {
return webView
}
func updateUIView(_ uiView: UIView, context: Context) {}
}
I have an app using TabView with multiple Tabs using tabViewStyle „sidebarAdaptable“.
Each Tab does have its own NavigationStack.
When I switch multiple times between the tabs and append a child view to one of my navigation stacks, it will stop working after a few tries with the following error
„A NavigationLink is presenting a value of type “HomeStack” but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated.
Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView.“
The same code is working fine on iOS, iPadOS but not working on macOS.
When I remove tabViewStyle of sidebarAdaptable it’s also working on macOS.
I shrinked it down to a minimal reproducible code sample.
Any idea if that is a bug or I'm doing something wrong?
struct ContentView: View {
@State private var appState: AppState = .init()
var body: some View {
TabView(selection: $appState.rootTab) {
Tab("Home", systemImage: "house", value: RootTab.home) {
NavigationStack(path: $appState.homeStack) {
Text("Home Stack")
NavigationLink("Item 1", value: HomeStack.item1)
.padding()
NavigationLink("Item 2", value: HomeStack.item2)
.padding()
.navigationDestination(for: HomeStack.self) { stack in
Text("Stack \(stack.rawValue)")
}
.navigationTitle("HomeStack")
}
}
Tab("Tab1", systemImage: "gear", value: RootTab.tab1) {
NavigationStack(path: $appState.tab1Stack) {
Text("Tab 1 Stack")
NavigationLink("Item 1", value: Tab1Stack.item1)
.padding()
NavigationLink("Item 2", value: Tab1Stack.item2)
.padding()
.navigationDestination(for: Tab1Stack.self) { stack in
Text("Stack \(stack.rawValue)")
}
.navigationTitle("Tab1Stack")
}
}
}
.tabViewStyle(.sidebarAdaptable)
.onChange(of: appState.rootTab) { _, _ in
appState.homeStack.removeAll()
appState.tab1Stack.removeAll()
}
}
}
@MainActor
@Observable
class AppState {
var rootTab: RootTab = .home
var homeStack: [HomeStack] = []
var tab1Stack: [Tab1Stack] = []
}
enum RootTab: Hashable {
case home
case tab1
case tab2
}
enum HomeStack: String, Hashable {
case home
case item1
case item2
}
enum Tab1Stack: String, Hashable {
case home
case item1
case item2
}
Hi! How can I create a toolbar animation in SwiftUI like the one shown at 16:54 in WWDC session?
I’ve got the new SwiftUi webview in a sheet. When I pull down the contents from the top of the page I expect it to dismiss the sheet, but it does not.
Is there a workaround or modifier I’m missing?
FB: FB19828741
Maybe I am doing something wrong with the new LiquidGlass sidebar using iPadOS 26 Beta 7, but when using this code, in stead of the List being centered between the sidebar and the rest of the screen, the cell itself extends beneath the sidebar but the content stays clear of the sidebar, giving a weird visual effect. Not my expected behavior at least.
Any ideas? Or just a bug?
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationSplitView {
Text("Test")
} detail: {
List {
Text("ContentMargin")
}
.contentMargins(.horizontal, 100.0)
}
}
}
#Preview {
ContentView()
}
This was on iPad OS 18:
I'm working with SwiftData and SwiftUI and it's not clear to me if it is good practice to have a @ModelActor directly populate a SwiftUI view. For example when having to combine manual lab results and clinial results from HealthKit. The Clinical lab results are an async operation:
@ModelActor
actor LabResultsManager {
func fetchLabResultsWithHealthKit() async throws -> [LabResultDto] {
let manualEntries = try modelContext.fetch(FetchDescriptor<LabResult>())
let clinicalLabs = (try? await HealthKitService.getLabResults()) ?? []
return (manualEntries + clinicalLabs).sorted {
$0.date > $1.date
}.map {
return LabResultDto(from: $0)
}
}
}
struct ContentView: View {
@State private var labResults: [LabResultDto] = []
var body: some View {
List(labResults, id: \.id) { result in
VStack(alignment: .leading) {
Text(result.testName)
Text(result.date, style: .date)
}
}
.task {
do {
let labManager = LabResultsManager()
labResults = try await labManager.fetchLabResultsWithHealthKit()
} catch {
// Handle error
}
}
}
}
EDIT:
I have a few views that would want to use these labResults so I need an implementation that can be reused. Having to fetch and combine in each view will not be good practice. Can I pass a modelContext to a viewModel?
The calendar widget and buttons shows a lightened / material background behind some content when the widget is in clear / tinted mode (example here: https://developer.apple.com/videos/play/wwdc2025/278?time=72).
How can this be done? I tried applying a material and glass background to a view using the .background(...) modifier, but the background is made white.
Text("Hello")
.padding()
.background {
ContainerRelativeShape()
.fill(.thinMaterial)
}
Text("Hello")
.padding()
.background {
ContainerRelativeShape()
.glassEffect()
}
Is this not supported, a bug, or am I doing something wrong?
Hello Folks,
what's causing the "smart" dismiss after shareLink? this only happens when saving the photos.
view -> opens a popover -> sharelink -> save to photo -> Allow photo Access -> ✅
view -> opens a popover -> sharelink -> save to photo -> [Observe popover dismisses ❌] popover should stay open
Remember to add INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = save to album in project settings
import SwiftUI
@main
struct sharepopoverDismissApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State private var showingSharePopover = false
@State private var urlToShare: URL = Bundle.main.url(forResource: "BigBuckBunny", withExtension: "mp4") ?? URL(string: "https://www.example.com")!
var body: some View {
VStack {
Button {
showingSharePopover = true
} label: {
Label("Show Share Options", systemImage: "square.and.arrow.up")
.font(.title2)
.padding(.vertical, 10)
.padding(.horizontal, 20)
}
.buttonStyle(.borderedProminent)
.tint(.indigo)
.controlSize(.large)
.shadow(radius: 5)
.popover(isPresented: $showingSharePopover, attachmentAnchor: .point(.center)) {
ShareLinkPopoverView(url: urlToShare)
}
}
.padding()
}
}
struct ShareLinkPopoverView: View {
let url: URL
var body: some View {
VStack(spacing: 20) {
ShareLink(item: url) {
Label("Share Now", systemImage: "square.and.arrow.up")
.font(.headline)
.padding(.vertical, 8)
.padding(.horizontal, 15)
}
.interactiveDismissDisabled()
.buttonStyle(.borderedProminent)
.tint(.green)
.controlSize(.regular)
}
.padding(20)
.presentationCompactAdaptation(.popover)
}
}
Take this piece of code for example:
Menu {
...
} label: {
Image(systemName: "ellipsis.circle")
.resizable()
.foregroundStyle(Color.primary)
.frame(width: 24, height: 24)
.contentShape(.circle)
.padding(.spacing8)
.glassEffect(.regular.interactive(), in: .circle)
}
.tint(nil)
When tapped, the interactive liquid glass effect expands in response, but the expanded glass is then clipped by the original bounds of the view. In this example, the button would briefly show up as a highlighted square due to the clipping.
If I add enough padding around the Menu's label, the expanded glass effect is be able to show unclipped, but this feels like a hack.
Is this a bug in the framework, or am I doing something wrong? I have submitted FB19801519 with screen recording and demo project.
Hi everyone,
I’m working on implementing Live Activities in my app, and I’ve encountered an issue where the Live Activity updates work intermittently when the app is in the background. Sometimes they update correctly, but at other times, they don’t update at all, even though they should be running in the background.
However, when the app is brought to the foreground, the updates happen correctly.
A few things I’ve checked:
The app is using ActivityKit to update the Live Activity with Activity.update().
I’ve enabled the necessary background modes in the Capabilities section.
Is there a possibility that I’m hitting the system budget limit while experiencing this issue? If this is a limitation, how can I avoid it or manage this situation?
Has anyone else faced this issue? Any advice or potential solutions would be greatly appreciated!
Thank you!
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
Swift
SwiftUI
WidgetKit
ActivityKit
The default style for a segmented picker in iOS 26 is now a capsule shape. Is it possible to get back the previous rounded rectangle shape?
In SwiftUI I have tried using the clipShape, containerShape, and background modifiers, applying a RoundedRectangle shape with a corner radius, to no avail. In UIKit I have tried to adjust the corner configuration for the UISegmentedControl, also to no avail.
Am I missing something really obvious or is it impossible to change the style here? 🤔
When navigationTransition returns through the return gesture, the original view disappears。
The same problem occurs when using the official example。
https://developer.apple.com/documentation/swiftui/enhancing-your-app-content-with-tab-navigation
xcode Version 16.4 (16F6)
macOS 15.5