Search results for

“swiftui”

17,235 results found

Post

Replies

Boosts

Views

Activity

Reply to How to animate `UIHostingController.view` frame when my View's size changes?
Alright, I have tried to follow your advice and I don't see how this can help. I have this setup: struct AnimatedView: View { @ObservedObject var viewModel: ViewModel var body: some View { let width = viewModel.isExpanded ? 120.0 : 50.0 let height = viewModel.isExpanded ? 400.0 : 100.0 let cornerRadius = viewModel.isExpanded ? 42.0 : 8.0 Color(uiColor: .red) .frame(width: width, height: height) .cornerRadius(cornerRadius) } } The hosting controller is mounted to the top of its parent via constraints. Then I do this in my tap handler for a totally separate button: @objc func tap() { withAnimation(Animation.easeInOut(duration: 0.5), { viewModel.isExpanded.toggle() }) } And what I observe here is that my hosting controller's view immediately teleports to the new frame - its center is immediately in the position where it should be only at the end of the animation. Meanwhile, the SwiftUI content is animating correctly, except it has already teleported. I have tried to use your answer @DTS Engineer I have
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’26
Wrong position of searchable component on first render
Hey all, I found a weird behaviour with the searchable component. I created a custom bottom nav bar (because I have custom design in my app) to switch between screens. On one screen I display a List component with the searchable component. Whenever I enter the search screen the first time, the searchable component is displayed at the bottom. This is wrong. It should be displayed at the top under the navigationTitle. When I enter the screen a second time, everything is correct. This behaviour can be reproduced on all iOS 26 versions on the simulator and on a physical device with debug and release build. On iOS 18 everything works fine. Steps to reproduce: Cold start of the app Click on Search TabBarIcon (searchable wrong location) Click on Home TabBarIcon Click on Search TabBarIcon (searchable correct location) Simple code example: import SwiftUI struct ContentView: View { @State var selectedTab: Page = Page.main var body: some View { NavigationStack { ZStack { VStack { switch selectedTab { case .main
5
0
337
Jan ’26
Reply to SwiftUI view state resetting after alert is shown
Thanks for the follow ups. Can’t believe I’m not reproducing so let me take a step back and let’s get this to reproduce. Based on your description, it seems that the inside the is being recreated when the flag changes, causing issues in your SwiftUI view. This behavior might occur because SwiftUI re-evaluates views when state changes, and if the identity of views isn’t stable, it can lead to unnecessary recreations. What Xcode build do you use and what iOS simulator do you use? Can we get this in a focused sample so I can download and run it in different Xcode versions? And also will be good if other SwiftUI engineers take a look because I’m failing to reproduce it, so something I am not doing correctly. If the static text doesn’t recreate, the issue might be related to how handles state updates. Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI
Jan ’26
Reply to TextEditor scroll to selection
Thanks for your question and post. I hope I can understand exactly what you mean by scrolling. Do you mean scrolling inside a Text? Scrolling to the cursor position in a TextEditor in SwiftUI? Or like with UITextView in UIKit? Do you mean scrolling to a specific part of the text? // Something like this? TextEditor(text: $text) .background( GeometryReader { geometry -> Color in (...) ) To provide a more accurate response, I would appreciate it if you could provide additional context and some code snippets. This will enable us to understand your specific requirements and the exact functionality you are seeking to achieve. Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI
Jan ’26
UIKit equivalent of SwiftUI .tabRole(.search)?
In SwiftUI, iOS 18+ provides a dedicated Search tab role: Tab(value: .search, role: .search) { Text(This view is intentionally blank) } This displays Search as a separate tab bar item/slot. Is there an official UIKit equivalent for UITabBarController / UITabBarItem? If not, what is Apple’s recommended UIKit approach to achieve the same UX?
Topic: UI Frameworks SubTopic: UIKit
1
0
158
Jan ’26
macOS SwiftUI app with external 4K camera & sensors for Hospital Avatar: ARKit, MLX, and Thermal feasibility?
We are developing a standalone AI avatar application for hospital reception kiosks using Mac mini (M2/M4). The app runs on SwiftUI + RealityKit, displays on a 75-inch monitor, and utilizes a USB-connected 4K camera and external sensors (LiDAR/mmWave). We have several technical concerns regarding the transition from iPadOS to macOS. Could you please provide insights on the following? ARKit/Vision Framework on macOS with External Camera On iPadOS, ARKit provides robust Face Tracking. On macOS with an external USB 4K camera: Can we achieve real-time face tracking (expression/gaze/depth) with Vision framework or ARKit comparable to iPadOS performance? Are there any specific limitations for accessing the Neural Engine via Vision framework for real-time 4K video analysis on macOS? Accessing External Hardware (LiDAR/Sensors) in Sandbox We plan to connect external LiDAR and mmWave sensors (e.g., Akara) via USB/Bluetooth. Is it feasible to communicate with these custom drivers/devices within the App Sandbox e
0
0
466
Jan ’26
Reply to SwiftUI iOS 26 .safeAreaBar issue with large navigation title
I think the question remains; where is .safeAreaBar supposed to be placed, when you're using a ScrollView on the page? I'm also using the .top setting. I haven't been able to find some usage example of this. It seems that if we attach the .safeAreaBar onto the scrollview itself, the scrollview content is correctly offset at first, such that the safeareabar contents do not overlap the scrollviews unless scrolled. If we put the safeareabar higher in the hierarchy, the scrollview contents are not offset and we unfortunately get overlap. Would help a ton to get some insight here. As a workaround, perhaps it would work by putting the safeareabar high in the hierarchy (like onto the first view in the SwiftUI view body), and then manually offsetting the scrollview offset somehow. Still need to figure out how to find the correct offset here...
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’26
SwiftUI: UNUserNotificationCenter delegate not called on cold start when opening notification
I'm sending local push notifications and want to show specific content based on the id of any notification the user opens. I'm able to do this with no issues when the app is already running in the background using the code below. final class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate { let container = AppContainer() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { let center = UNUserNotificationCenter.current() center.delegate = self return true } func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) { container.notifications.handleResponse(response) completionHandler() } } However, the delegate never fires if the app was terminated before the user taps the notification. I'm looking for a way to fix this without switching my app lifecycle to UIKit. This is a SwiftUI
0
0
312
Jan ’26
Reply to SwiftUI view state resetting after alert is shown
Thank you for sharing your post. I find it intriguing, but I am unable to replicate the functionality you have described on my own devices. The code works the same in all simulators I have tried. The parent SwiftUI view is a List, which is destroyed when nested view presentations and alerts are involved. While you mentioned that it works correctly on other simulators and devices, I have consistently encountered the same issue when running it on different simulators with the same configuration. I would personally implement a custom mechanism to manage when and how the sheet is presented, potentially using a combination of state flags and conditional views to avoid relying on the immediate modifier behavior or better, do not include inside a List that will be destroyed. I am still very interested in knowing what device and versions of iOS the code: List { VStack { LibraryView(title: “Show view (Loss of state)”) } } works so that I can investigate the reason, in my case, the state did not work in any si
Topic: UI Frameworks SubTopic: SwiftUI
Jan ’26
SwiftUI view state resetting after alert is shown
Seeing an issue in iOS 26.2 iPhone 17 simulator (haven't been able to reproduce on device or other simulators), where a view's state is reset after an alert is shown. In this example the first LibraryView has the issue when alert is shown, the second LibraryView maintains state as expected. struct ContentView: View { var body: some View { NavigationStack { List { VStack { LibraryView(title: Show view (Loss of state)) } LibraryView(title: Show view (Works as expected)) } } } } /// This view is from a package dependency and wants to control the presentation of the sheet internally public struct LibraryView: View { @State private var isPresented: Bool = false let title: String public init(title: String) { self.title = title } public var body: some View { Button(self.title) { self.isPresented = true } .sheet(isPresented: self.$isPresented) { ViewWithAlert() } } } private struct ViewWithAlert: View { @State private var isPresented: Bool = false @State private var presentedCount = 0 var body: some View { Button(Sho
Topic: UI Frameworks SubTopic: SwiftUI
11
0
460
Jan ’26
Reply to State loss and sheets dismiss on backgrounding app
Thanks for the post, this is very interesting. And thanks for the bug where includes the focused project sample. Navigating complex hierarchies in SwiftUI while maintaining state can indeed be challenging. I can try to suggest some potential workarounds and strategies to mitigate state loss issues during navigation and app backgrounding but I also want to see this issue and use your focus sample to see how the sheets are lost after being presented on the app and to see if moving state management to a parent view is the answer and understand how the views are not being shown after the background. Passing state down through view hierarchies can ensure it's retained longer than if it were localized in deeply nested views. If you're not already on the latest SwiftUI and iOS version, consider updating to see if the issue has been addressed in more recent releases. Additionally, beta versions can sometimes provide pre-release fixes. You can see the status of your feedback in Feedback Assistant. Th
Topic: UI Frameworks SubTopic: SwiftUI
Jan ’26
State loss and sheets dismiss on backgrounding app
I've been hitting a weird SwiftUI bug with navigation and state loss and I've managed to reproduce in a very tiny sample project. I've submitted a Feedback FB21681608 but thought it was worth posting here incase any SwiftUI experts can see something obviously wrong. The bug With deeper levels of navigation hierarchy SwiftUI will dismiss views when backgrounding the app. Any work around would be appreciated. This happens in a real app where we have to navigate to a settings screen modally and then a complex flow with other sheets. Sample code Happens in the simulator and on device. import SwiftUI struct ContentView: View { @State private var isPresented = false var body: some View { Button(Show first sheet) { isPresented = true } .sheet(isPresented: $isPresented) { SheetView(count: 1) } } } struct SheetView: View { private enum Path: Hashable { case somePath } @State private var isPresented = false var count: Int var body: some View { NavigationStack { VStack { Text(Sheet (c
Topic: UI Frameworks SubTopic: SwiftUI
3
0
251
Jan ’26
Reply to Custom @Observable RandomAcccessCollection List/ForEach issues
I learned my lesson to not color outside the lines with pure SwiftUI. I've not tried it again since April, so maybe something changed with the Xcode releases since then, but I just export pure arrays from my view models instead of trying to be clever with custom collections. It would be cool if it were predictably extensible, but there's too much goddamn magic going on to waste time with it in my opinion.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’26
Reply to How to animate `UIHostingController.view` frame when my View's size changes?
Alright, I have tried to follow your advice and I don't see how this can help. I have this setup: struct AnimatedView: View { @ObservedObject var viewModel: ViewModel var body: some View { let width = viewModel.isExpanded ? 120.0 : 50.0 let height = viewModel.isExpanded ? 400.0 : 100.0 let cornerRadius = viewModel.isExpanded ? 42.0 : 8.0 Color(uiColor: .red) .frame(width: width, height: height) .cornerRadius(cornerRadius) } } The hosting controller is mounted to the top of its parent via constraints. Then I do this in my tap handler for a totally separate button: @objc func tap() { withAnimation(Animation.easeInOut(duration: 0.5), { viewModel.isExpanded.toggle() }) } And what I observe here is that my hosting controller's view immediately teleports to the new frame - its center is immediately in the position where it should be only at the end of the animation. Meanwhile, the SwiftUI content is animating correctly, except it has already teleported. I have tried to use your answer @DTS Engineer I have
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’26
Wrong position of searchable component on first render
Hey all, I found a weird behaviour with the searchable component. I created a custom bottom nav bar (because I have custom design in my app) to switch between screens. On one screen I display a List component with the searchable component. Whenever I enter the search screen the first time, the searchable component is displayed at the bottom. This is wrong. It should be displayed at the top under the navigationTitle. When I enter the screen a second time, everything is correct. This behaviour can be reproduced on all iOS 26 versions on the simulator and on a physical device with debug and release build. On iOS 18 everything works fine. Steps to reproduce: Cold start of the app Click on Search TabBarIcon (searchable wrong location) Click on Home TabBarIcon Click on Search TabBarIcon (searchable correct location) Simple code example: import SwiftUI struct ContentView: View { @State var selectedTab: Page = Page.main var body: some View { NavigationStack { ZStack { VStack { switch selectedTab { case .main
Replies
5
Boosts
0
Views
337
Activity
Jan ’26
Reply to SwiftUI view state resetting after alert is shown
Thanks for the follow ups. Can’t believe I’m not reproducing so let me take a step back and let’s get this to reproduce. Based on your description, it seems that the inside the is being recreated when the flag changes, causing issues in your SwiftUI view. This behavior might occur because SwiftUI re-evaluates views when state changes, and if the identity of views isn’t stable, it can lead to unnecessary recreations. What Xcode build do you use and what iOS simulator do you use? Can we get this in a focused sample so I can download and run it in different Xcode versions? And also will be good if other SwiftUI engineers take a look because I’m failing to reproduce it, so something I am not doing correctly. If the static text doesn’t recreate, the issue might be related to how handles state updates. Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jan ’26
Reply to TextEditor scroll to selection
Thanks for your question and post. I hope I can understand exactly what you mean by scrolling. Do you mean scrolling inside a Text? Scrolling to the cursor position in a TextEditor in SwiftUI? Or like with UITextView in UIKit? Do you mean scrolling to a specific part of the text? // Something like this? TextEditor(text: $text) .background( GeometryReader { geometry -> Color in (...) ) To provide a more accurate response, I would appreciate it if you could provide additional context and some code snippets. This will enable us to understand your specific requirements and the exact functionality you are seeking to achieve. Albert Pascual
  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jan ’26
TextEditor scroll to selection
How can I scroll to TextEditor cursor position in SwiftUI
Topic: UI Frameworks SubTopic: SwiftUI
Replies
2
Boosts
0
Views
368
Activity
Jan ’26
UIKit equivalent of SwiftUI .tabRole(.search)?
In SwiftUI, iOS 18+ provides a dedicated Search tab role: Tab(value: .search, role: .search) { Text(This view is intentionally blank) } This displays Search as a separate tab bar item/slot. Is there an official UIKit equivalent for UITabBarController / UITabBarItem? If not, what is Apple’s recommended UIKit approach to achieve the same UX?
Topic: UI Frameworks SubTopic: UIKit
Replies
1
Boosts
0
Views
158
Activity
Jan ’26
macOS SwiftUI app with external 4K camera & sensors for Hospital Avatar: ARKit, MLX, and Thermal feasibility?
We are developing a standalone AI avatar application for hospital reception kiosks using Mac mini (M2/M4). The app runs on SwiftUI + RealityKit, displays on a 75-inch monitor, and utilizes a USB-connected 4K camera and external sensors (LiDAR/mmWave). We have several technical concerns regarding the transition from iPadOS to macOS. Could you please provide insights on the following? ARKit/Vision Framework on macOS with External Camera On iPadOS, ARKit provides robust Face Tracking. On macOS with an external USB 4K camera: Can we achieve real-time face tracking (expression/gaze/depth) with Vision framework or ARKit comparable to iPadOS performance? Are there any specific limitations for accessing the Neural Engine via Vision framework for real-time 4K video analysis on macOS? Accessing External Hardware (LiDAR/Sensors) in Sandbox We plan to connect external LiDAR and mmWave sensors (e.g., Akara) via USB/Bluetooth. Is it feasible to communicate with these custom drivers/devices within the App Sandbox e
Replies
0
Boosts
0
Views
466
Activity
Jan ’26
Reply to SwiftUI iOS 26 .safeAreaBar issue with large navigation title
I think the question remains; where is .safeAreaBar supposed to be placed, when you're using a ScrollView on the page? I'm also using the .top setting. I haven't been able to find some usage example of this. It seems that if we attach the .safeAreaBar onto the scrollview itself, the scrollview content is correctly offset at first, such that the safeareabar contents do not overlap the scrollviews unless scrolled. If we put the safeareabar higher in the hierarchy, the scrollview contents are not offset and we unfortunately get overlap. Would help a ton to get some insight here. As a workaround, perhaps it would work by putting the safeareabar high in the hierarchy (like onto the first view in the SwiftUI view body), and then manually offsetting the scrollview offset somehow. Still need to figure out how to find the correct offset here...
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’26
SwiftUI: UNUserNotificationCenter delegate not called on cold start when opening notification
I'm sending local push notifications and want to show specific content based on the id of any notification the user opens. I'm able to do this with no issues when the app is already running in the background using the code below. final class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate { let container = AppContainer() func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { let center = UNUserNotificationCenter.current() center.delegate = self return true } func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) { container.notifications.handleResponse(response) completionHandler() } } However, the delegate never fires if the app was terminated before the user taps the notification. I'm looking for a way to fix this without switching my app lifecycle to UIKit. This is a SwiftUI
Replies
0
Boosts
0
Views
312
Activity
Jan ’26
Reply to SwiftUI view state resetting after alert is shown
Thank you for sharing your post. I find it intriguing, but I am unable to replicate the functionality you have described on my own devices. The code works the same in all simulators I have tried. The parent SwiftUI view is a List, which is destroyed when nested view presentations and alerts are involved. While you mentioned that it works correctly on other simulators and devices, I have consistently encountered the same issue when running it on different simulators with the same configuration. I would personally implement a custom mechanism to manage when and how the sheet is presented, potentially using a combination of state flags and conditional views to avoid relying on the immediate modifier behavior or better, do not include inside a List that will be destroyed. I am still very interested in knowing what device and versions of iOS the code: List { VStack { LibraryView(title: “Show view (Loss of state)”) } } works so that I can investigate the reason, in my case, the state did not work in any si
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jan ’26
SwiftUI view state resetting after alert is shown
Seeing an issue in iOS 26.2 iPhone 17 simulator (haven't been able to reproduce on device or other simulators), where a view's state is reset after an alert is shown. In this example the first LibraryView has the issue when alert is shown, the second LibraryView maintains state as expected. struct ContentView: View { var body: some View { NavigationStack { List { VStack { LibraryView(title: Show view (Loss of state)) } LibraryView(title: Show view (Works as expected)) } } } } /// This view is from a package dependency and wants to control the presentation of the sheet internally public struct LibraryView: View { @State private var isPresented: Bool = false let title: String public init(title: String) { self.title = title } public var body: some View { Button(self.title) { self.isPresented = true } .sheet(isPresented: self.$isPresented) { ViewWithAlert() } } } private struct ViewWithAlert: View { @State private var isPresented: Bool = false @State private var presentedCount = 0 var body: some View { Button(Sho
Topic: UI Frameworks SubTopic: SwiftUI
Replies
11
Boosts
0
Views
460
Activity
Jan ’26
Reply to State loss and sheets dismiss on backgrounding app
Thanks for the post, this is very interesting. And thanks for the bug where includes the focused project sample. Navigating complex hierarchies in SwiftUI while maintaining state can indeed be challenging. I can try to suggest some potential workarounds and strategies to mitigate state loss issues during navigation and app backgrounding but I also want to see this issue and use your focus sample to see how the sheets are lost after being presented on the app and to see if moving state management to a parent view is the answer and understand how the views are not being shown after the background. Passing state down through view hierarchies can ensure it's retained longer than if it were localized in deeply nested views. If you're not already on the latest SwiftUI and iOS version, consider updating to see if the issue has been addressed in more recent releases. Additionally, beta versions can sometimes provide pre-release fixes. You can see the status of your feedback in Feedback Assistant. Th
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jan ’26
State loss and sheets dismiss on backgrounding app
I've been hitting a weird SwiftUI bug with navigation and state loss and I've managed to reproduce in a very tiny sample project. I've submitted a Feedback FB21681608 but thought it was worth posting here incase any SwiftUI experts can see something obviously wrong. The bug With deeper levels of navigation hierarchy SwiftUI will dismiss views when backgrounding the app. Any work around would be appreciated. This happens in a real app where we have to navigate to a settings screen modally and then a complex flow with other sheets. Sample code Happens in the simulator and on device. import SwiftUI struct ContentView: View { @State private var isPresented = false var body: some View { Button(Show first sheet) { isPresented = true } .sheet(isPresented: $isPresented) { SheetView(count: 1) } } } struct SheetView: View { private enum Path: Hashable { case somePath } @State private var isPresented = false var count: Int var body: some View { NavigationStack { VStack { Text(Sheet (c
Topic: UI Frameworks SubTopic: SwiftUI
Replies
3
Boosts
0
Views
251
Activity
Jan ’26
I can not find the swiftui inspector
I can't find the full content of the SwiftUI inspector in the latest version of Xcode. I've opened the preview canvas but it still won't display.
Replies
0
Boosts
0
Views
151
Activity
Jan ’26
Reply to Custom @Observable RandomAcccessCollection List/ForEach issues
I learned my lesson to not color outside the lines with pure SwiftUI. I've not tried it again since April, so maybe something changed with the Xcode releases since then, but I just export pure arrays from my view models instead of trying to be clever with custom collections. It would be cool if it were predictably extensible, but there's too much goddamn magic going on to waste time with it in my opinion.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’26