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

Posts under SwiftUI tag

200 Posts

Post

Replies

Boosts

Views

Activity

"The compiler is unable to type-check this expression..."
"/Users/rich/Work/IdeaBlitz/IdeaBlitz/IdeaListView.swift:30:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions" Is it just me? I get this on syntax errors, missing commas, missing quotes, and for no particular reason at all that I can see. I don't think I've been able to write a single, simple, SwiftUI view without seeing this multiple times. "Breaking it up" just makes it harder to read. Simple, inline, 2-page views become 8-page, totally unreadable, monstrosities. Am I doing something wrong? Or is this just the state of SwiftUI today? Or is there some way to tell the compiler to take more time on this expression? I mean, if these can be broken up automatically, then why doesn't the compiler to that already?
3
0
185
2h
visionOS – Starting GroupActivity FaceTime Call dismisses Immersive Space
Hello, I am in the process of implementing SharePlay support in my visionOS app. Everything runs fine when I test locally, but when my app is distributed via TestFlight, calling try await activity.activate() shows the SharePlay dialog as usual, but then when I start a new FaceTime call, my ImmersiveSpace gets dismissed. This is only happening when the app is distributed via TestFlight, when I run it locally the ImmersiveSpace stays active as expected. Looking at the console on my Mac I found this log: Invalid initial client settings class: UIApplicationSceneClientSettings; expected class: MRUISharedApplicationSceneClientSettings; bundle ID: com.apple.facetime; scene ID: com.apple.facetime:SFBSystemService-DDA8C751-C0C4-487E-AD85-59EF4E6C6050 Does anyone have an idea how I can fix this? It's driving me nuts and I wasted over a day looking for a workaround but so far been unsuccessful. Thanks!
2
0
119
2h
Combining NavigationSplitView and TabView in iOS 18
Hi folks, I've used a NavigationSplitView within one of the tabs of my app since iOS 16, but with the new styling in iOS 18 the toolbar region looks odd. In other tabs using e.g. simple stacks, the toolbar buttons are horizontally in line with the new tab picker, but with NavigationSplitView, the toolbar leaves a lot of empty space at the top (see below). Is there anything I can do to adjust this, or alternatively, continue to use the old style? Thanks!
12
3
2.7k
7h
iOS 26 (beta 7) setting .searchFocused programmatically does not work
Already filed a feedback in case this is a bug, but posting here in case I'm doing something wrong? I'd like the search field to automatically be displayed with the keyboard up when the view appears. This sample code works in iOS 18, but it does not work in iOS 26 beta 7 I also tried adding a delay to setting searchIsFocused = true but that did not help struct ContentView: View { var body: some View { NavigationStack { NavigationLink(destination: ListView()) { Label("Go to list", systemImage: "list.bullet") } } .ignoresSafeArea() } } struct ListView: View { @State private var searchText: String = "" @State private var searchIsPresented: Bool = false @FocusState private var searchIsFocused: Bool var body: some View { ScrollView { Text("Test") } .searchable(text: $searchText, isPresented: $searchIsPresented, placement: .automatic, prompt: "Search") .searchFocused($searchIsFocused) .onAppear { searchIsFocused = true } } }
5
1
145
21h
Unable to apply liquid glass effect on popover that is opened from a liquid glass container
When a popover is presented from a view that uses glassEffect(.regular.interactive()), I’m seeing mutually exclusive behavior: either the popover’s chrome (its navigation bar / toolbar) uses Liquid Glass or the originating control keeps its Liquid Glass “morph” behavior — but not both at the same time. There are two ways that I can enable Liquid Glass on the container: Option 1 (background capsule with .glassEffect) → The popover’s toolbar shows Liquid Glass, but the menu button loses its morph effect. Option 2 (.glassEffect applied to the HStack) → The menu button keeps the morph effect, but the popover’s toolbar does not have Liquid Glass. I'm using XCode 26.0.1, with latest iOS 26.0 stable simulator installed. Here's an example code to reproduce the issue: import PlaygroundSupport import SwiftUI // MARK: - TestView struct TestView: View { @State private var isPresented = false var body: some View { VStack { Spacer() HStack { Button("", systemImage: "plus") { isPresented = true } .popover(isPresented: $isPresented) { MyPopover() } Menu { Button("Option 1", action: {}) Button("Option 2", action: {}) Button("Option 3", action: {}) } label: { Image(systemName: "ellipsis") .frame(width: 40, height: 40) } } .padding(.horizontal) // Option 1 - The popover's toolbar will have liquid glass effect, but then the menu button loses liquid glass morph effect .background { Capsule() .fill(Color.white) .glassEffect(.regular.interactive()) } // Option 2 - The popover's toolbar will not have liquid glass effect, but the menu button keeps liquid glass morph effect // .glassEffect(.regular.interactive()) Spacer() } .frame(width: 400, height: 800) } } // MARK: - MyPopover private struct MyPopover: View { var body: some View { NavigationStack { VStack { ScrollView { Text( "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." ) .padding(.horizontal) } } .navigationTitle("Welcome") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .cancellationAction) { Button("", systemImage: "xmark", action: {}) } } } .presentationCompactAdaptation(.popover) .frame(width: 300, height: 200) } } PlaygroundPage.current.setLiveView( TestView() ) Attached the screenshots for the difference.
1
0
33
21h
Is ContactAccessButton broken?
Simple question - on iOS 26 ContactAccessButton does not appear to show any UI when attempting to search for a contact in either the contact access picker on the ContactAccessButton. This behavior occurs in the Apple provided sample code , as well as a basic example: struct ContentView: View { @State var searchText : String = "" var body: some View { VStack { TextField("Search", text: $searchText) ContactAccessButton( queryString: searchText, ignoredEmails: nil, ignoredPhoneNumbers: nil, approvalCallback: { identifiers in print(identifiers) }) } .padding() } } Am I doing something wrong or is this just not working?
0
0
28
1d
What is the new name of the OSDUIHelper process on macOS Tahoe?
I am currently developing a macOS app that can show system HUDs in the Notch Till Sequoia I used to kill the OSDUIHelper process (which displays the default macOS Volume and Brightness control HUDs) - and replaced it with my app's HUDs But, it is not working on macOS Tahoe anymore as the OSDUIHelper process is no longer there due to the UI changes Has the process been renamed - or is there any other way to kill the process?
0
0
22
1d
Is it still possible to change the color of unselected icons in a TabView?
Hi. I‘m making an app with SwiftUI for iOS 26, and found that the old ways of changing unselected icons color seem not working as they did in old versions of iOS. I tried these methods: TabView() { Tab { // some view here } label: { Label(title: { Text("something") }, icon: { Image(systemName: "checkmark.seal.fill") .foregroundStyle(.blue) } } } I wrapped Image with an if-else, but itisn't able to change any color even without if; struct ParentView: View { init() { UITabBar.appearance() .unselectedItemTintColor = UIColor.red } var body: some View { TabView() { // some tabs here } } } and an extension of above struct ParentView: View { init() { let tabBarAppearance = UITabBarAppearance() tabBarAppearance.configureWithOpaqueBackground() tabBarAppearance.backgroundColor = UIColor.green tabBarAppearance.stackedLayoutAppearance .selected.titleTextAttributes = [.foregroundColor: UIColor.red] tabBarAppearance.stackedLayoutAppearance.normal .titleTextAttributes = [.foregroundColor: UIColor.black] tabBarAppearance.stackedLayoutAppearance .normal.iconColor = UIColor.black tabBarAppearance.stackedLayoutAppearance .selected.iconColor = UIColor.red UITabBar.appearance() .scrollEdgeAppearance = tabBarAppearance UITabBar.appearance() .standardAppearance = tabBarAppearance UITabBar.appearance() .unselectedItemTintColor = .black } var body: some View { TabView() { // some tabs here } } } I read about this from reddit https://www.reddit.com/r/iOSProgramming/comments/1ftmfoa/tabbartabview_icon_and_text_colors_in_ios_18/, it successfully changes the color of the texts in the tabbar, but not the icons. After these, GitHub Copilot suggested me to draw two versions of icons, for different colors, which does work, but out of my capabilities. Is there any other ways to do this on new systems? Thank you very much for any replies.
1
0
68
1d
White flash using manageSubscriptionsSheet in SwiftUI
In SwiftUI I am using the manageSubscriptionsSheet modifier to open the iOS subscription screen. When this is presented it immediately flashes a white view and then animated the subscription screen up from the bottom, it looks pretty bad. The view I am calling manageSubscriptionsSheet on is presented in a sheet, so maybe trying to present the subscriptions view as well is causing the visual glitch. Any way to not have this white flashing view when opening the subscription screen?
0
0
93
2d
Extract Subview option missing in Xcode 26
Hi everyone, I recently updated to Xcode 26.0 and noticed that the “Extract Subview” refactoring option seems to be missing. Now, in Xcode 26, the only options I see under Editor -> Refactor -> are: Extract to Selection File Extract to Method Extract to Variable Extract All Occurrences But there’s no Extract Subview as there was before. Was Extract Subview intentionally removed in Xcode 26? Or is it hidden behind a new menu location or renamed?
5
5
348
2d
Present confirmationDialog from swipeActions in List
Hello, We use the .confirmationDialog() view modifier to present an alert when deleting an item in a list. Prior to iOS 26, this dialog appeared as an action sheet on iPhone. Following WWDC 25, my understanding is that on iOS 26 the dialog should appear as an action sheet over the originating view on iPhone. This is the behavior we observe in the built-in Messages and Mail apps when deleting an item (see the screenshot below). However, when using .confirmationDialog() on iOS 26, the dialog is displayed as a standard popover on iPhone. I haven’t been able to reproduce the new expected behavior. Here's a sample code: struct ContentView: View { @State var data: [String] = ["A", "B", "C"] @State var confirmationPresented: Bool = false var body: some View { List { ForEach(data, id: \.self) { item in Text(item) .confirmationDialog("Title", isPresented: $confirmationPresented, actions: { Button(action: { }, label: { Text("OK") }) }) .swipeActions { Button("Delete", systemImage: "trash", action: { confirmationPresented.toggle() }) .tint(Color.red) } } } } } Here's the result from this sample code: Is there an additional modifier or configuration required to enable the action sheet presentation on iPhone in iOS 26?
2
1
138
2d
Menu presentation in UIHostingController issues
Looking to see if anyone has experienced this issue, and is aware of any workarounds. With an app migrating towards SwiftUI Views but still using UIKit for primary navigation, my app makes use of UIHostingController to push SwiftUI Views onto a UINavigationController stack in a lot of areas. With iOS 26, I notice that SwiftUI's Menu view really struggles to present when contained in a UIHostingController. An error is logged to the console on presentation, and depending on the UI, the Menu won't present inside of it's container, or will jump around the screen. The bug, it seems is based in a private class UIReparentingView and I am curious if anyone has found a work around for this issue. The error reported is: Adding '_UIReparentingView' as a subview of UIHostingController.view is not supported and may result in a broken view hierarchy. Add your view above UIHostingController.view in a common superview or insert it into your SwiftUI content in a UIViewRepresentable instead. The simplest way to see this issue is to create a new storyboard based project. From the ViewController present a UIHostingController with a SwiftUI view that has a Menu and then simply tap to open the Menu. Thanks for any input!
6
2
240
2d
WKWebView Crashes on iOS During YouTube Playlist Playback
I’m encountering a consistent crash in WebKit when using WKWebView to play a YouTube playlist in my iOS app. Playback starts successfully, but the web process terminates during the second video in the playlist. This only occurs on physical devices, not in the simulator. Here’s a simplified Swift example of my setup: import SwiftUI import WebKit struct ContentView: View { private let playlistID = "PLig2mjpwQBZnghraUKGhCqc9eAy0UbpDN" var body: some View { YouTubeWebView(playlistID: playlistID) .edgesIgnoringSafeArea(.all) } } struct YouTubeWebView: UIViewRepresentable { let playlistID: String func makeUIView(context: Context) -> WKWebView { let config = WKWebViewConfiguration() config.allowsInlineMediaPlayback = true let webView = WKWebView(frame: .zero, configuration: config) webView.scrollView.isScrollEnabled = true let html = """ <!doctype html> <html> <head> <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0"> <style>body,html{height:100%;margin:0;background:#000}iframe{width:100%;height:100%;border:0}</style> </head> <body> <iframe src="https://www.youtube-nocookie.com/embed/videoseries?list=\(playlistID)&controls=1&rel=0&playsinline=1&iv_load_policy=3" frameborder="0" allow="encrypted-media; picture-in-picture; fullscreen" webkit-playsinline allowfullscreen ></iframe> </body> </html> """ webView.loadHTMLString(html, baseURL: nil) return webView } func updateUIView(_ uiView: WKWebView, context: Context) {} } #Preview { ContentView() } Observed behavior: First video plays without issue. Web process crashes when the second video in the playlist starts. Console logs show WebProcessProxy::didClose and repeated memory status messages. Using ProcessAssertion or background activity does not prevent the crash. Only occurs on physical devices; simulators do not reproduce the issue. Questions: Is there something I should change or add in my WKWebView setup or HTML/iframe to prevent the crash when playing the second video in a playlist on physical iOS devices? Is there an officially supported way to limit memory or prevent WebKit from terminating the web process during multi-video playback? Are there recommended patterns for playing YouTube playlists in a WKWebView on iOS without risking crashes? Any tips for debugging or configuring WKWebView to make it more stable for continuous playlist playback? Thanks in advance for any guidance!
2
0
293
2d
Crash while presenting popover on toolbar item in MacCatalyst app
struct ContentView: View { @State private var showingPopover:Bool = false private var popOverHeight: CGFloat { return 566 } var body: some View { NavigationStack { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() .toolbar { ToolbarItem(placement: .topBarTrailing) { Button { showingPopover = true } label: { Image(systemName: "plus") .font(Font.system(size: 15)) .foregroundColor(Color.red) } .popover(isPresented: $showingPopover) { FTShelfNewNotePopoverView1() .frame(minWidth: 340.0) .frame(height: popOverHeight) } } } } } }
0
0
177
2d
How can I optimize multilingual string translations in SwiftUI for App Store apps using Localization APIs?
Hi team, I’m developing an iOS app that helps manage and translate multilingual content . The app uses SwiftUI with Localizable.strings and Bundle.localizedString(forKey:). I’m trying to optimize for dynamic language switching inside the app without restarting. I’ve tested various methods like: Text(NSLocalizedString("welcome_text", comment: "")) and some approaches using @Environment(.locale), but the system doesn’t always update views instantly when language changes. Question: What’s the recommended approach (or WWDC reference) for real-time language change handling in SwiftUI apps targeting iOS 18+?
1
0
87
2d
How to display SegmentControl in tabViewBottomAccessory inline mode like iOS 26 Photos app?
Question I'm trying to replicate the iOS 26 Photos app behavior where a segmented control appears in the tab bar area when scrolling. Specifically, when the tab bar minimizes to inline mode, I want to show a Picker with .segmented style between the minimized tab button and search button. Expected Behavior (iOS 26 Photos App) When scrolling up in the Photos app: Tab bar minimizes to inline mode A segmented control (Years/Months/All) appears in the center Layout: [Tab Button] [Segmented Control] [Search Button] Current Implementation I'm using tabViewBottomAccessory with tabBarMinimizeBehavior: struct PhotosMainView: View { @Environment(ModelData.self) private var modelData @State private var searchText: String = "" var body: some View { @Bindable var modelData = modelData TabView { Tab("Library", systemImage: "photo.on.rectangle") { NavigationStack { PhotosGridView() .navigationTitle("Library") } } Tab("Albums", systemImage: "square.grid.2x2") { NavigationStack { AlbumsGridView() .navigationTitle("Albums") } } Tab("Search", systemImage: "magnifyingglass", role: .search) { NavigationStack { PhotosGridView() .navigationTitle("Search") .searchable(text: $searchText) } } } .tabBarMinimizeBehavior(.onScrollUp) .tabViewBottomAccessory { TimelineAccessoryView() .environment(modelData) } } } struct TimelineAccessoryView: View { @Environment(ModelData.self) private var modelData @Environment(\.tabViewBottomAccessoryPlacement) var placement var body: some View { Group { if let placement = placement { switch placement { case .inline: inlineView case .expanded: expandedView } } } } @ViewBuilder private var inlineView: some View { @Bindable var modelData = modelData Picker("View", selection: $modelData.timelineFilter) { Text("Years").tag(TimelineFilter.year) Text("Months").tag(TimelineFilter.month) Text("All").tag(TimelineFilter.all) } .pickerStyle(.segmented) .frame(maxWidth: 200) } @ViewBuilder private var expandedView: some View { Text("Expanded state") } } Issues Encountered 1. Console logs show placement changes correctly: placement: nil → expanded → inline 2. However, the segmented control doesn't appear visually in inline mode - The accessory view seems to render, but nothing is visible on screen - Only a small empty space appears where the control should be 3. AttributeGraph cycle warnings appear: === AttributeGraph: cycle detected through attribute 27160 === === AttributeGraph: cycle detected through attribute 26304 === What I've Tried 1. ✅ Separating inline/expanded views into @ViewBuilder properties to avoid cycles 2. ✅ Using .onAppear and .onChange for debugging instead of direct prints in body 3. ✅ Confirming placement environment value changes correctly 4. ❌ The segmented control still doesn't display in inline mode Questions 1. Is tabViewBottomAccessory the correct API to achieve this Photos app effect? 2. How should content be structured in .inline placement to display properly between tab button and search? 3. Are there additional modifiers or constraints needed for inline accessories? 4. Is there documentation or sample code showing this pattern? Environment - Xcode 17.0 - iOS 26.0 - iPhone 16 Simulator - SwiftUI Any guidance on the correct approach to implement this would be greatly appreciated. Thank you!
1
0
137
2d
Fous, FocusState and Architecture
I am currently struggling with resolving what appear to be competing design issues, and (while I may be just demonstrating my own ignorance) I would like to share my thoughts in the hope that you may have useful insights. For purposes of discussion, consider a large and complex data entry screen with multiple sections for input. For all of the usual reasons (such as reuse, performance management, etc) each of these sections is implemented as its own, separately-compiled View. The screen is, then, composed of a sequence of reusable components. However, each of these components has internal structure and may contain multiple focusable elements (and internal use of .onKeyPress(.tab) {...} to navigate internally). And the logic of each component is such that it has an internal @FocusState variable defined with its own unique type. So, obviously what I want is on the one hand, to provide a tab-based navigation scheme for the screen as a whole, where focus moves smoothly from one component's internals to the next component, and on the other hand ,to build components that don't know anything about each other and have no cross-component dependencies, so that they can be freely reused in different situations. And that's where I'm stuck. Since focus state variables for different components can have different types, a single over-arching FocusState passed (as a binding) to each component doesn't seem possible or workable. But I don't know how else to approach this issue. (Note: in UIKit, I've done things like this by direct manipulation of the Responder Chain, but I don't see how to apply this type of thinking to SwiftUI.) Thoughts?
3
0
124
2d
iOS 26: Navigation bar unexpectedly switches to Light appearance during navigation in Dark Mode
Summary On iOS 26, the navigation bar unexpectedly switches to a Light appearance during/after a view transition while the device/app is in Dark Mode. This seems correlated with applying listStyle(.plain) to a List. Removing .plain prevents the issue, but my app’s layout requires it. Sample code: import SwiftUI @main struct iOS26NavigationTitleSampleApp: App { var body: some Scene { WindowGroup { NavigationStack { ContentView() .navigationTitle("Root") .navigationBarTitleDisplayMode(.inline) } } } } struct ContentView: View { var body: some View { VStack { NavigationLink { ListView() } label: { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } } } .padding() .toolbar { ToolbarItemGroup(placement: .navigation) { Button("Test") { } Button("Test2") { } } } } } struct ListView: View { var items: [Int] = Array(0..<100) var body: some View { List { ForEach(items.indices, id: \.self) { idx in cell(items[idx]) } } .listStyle(.plain) .toolbar { ToolbarItemGroup(placement: .navigation) { Button("Test") { } Button("Test2") { } } } .navigationTitle("TTT") } private func cell(_ item: Int) -> some View { Text("\(item)") } } Steps to Reproduce: Set the device to Dark Mode. Launch the sample app. → The root view’s navigation bar is in Dark appearance (as expected). Tap “Hello World” to navigate. → On the destination view, the navigation bar becomes Light. Navigate back to the root view. → The root view’s navigation bar now also remains Light. Expected Result The navigation bar should consistently retain the Dark appearance throughout navigation. Notes Removing listStyle(.plain) stops the issue (navigation bar stays Dark). Simulator: Could not reproduce on iOS Simulator. Devices: Reproducible on physical device. Environment Device: iPhone 15 Plus OS: iOS 26 (23A341) Xcode: 26.0 (17A324)
5
0
314
3d