JUST ENDED
|

SwiftUI Q&A

Connect with Apple engineers in the SwiftUI Q&A on the Apple Developer Forums.

Post

Replies

Boosts

Views

Activity

Tab Bar behavior on resize
Good morning! Not sure this is strictly a SwiftUI question but it is a UI question. The biggest problems we’ve had in adopting the updated UI in recent releases center around the tab bar. We’re an iOS/iPadOS app with a tabbed UI. Having the tab bar arbitrarily jump from the bottom of the screen to the top at a certain size makes laying out our UI very difficult. We’ve worked around this so far by using a custom bar, but that’s clunky and doesn’t work well with Liquid Glass. Are there any changes to this behavior in the 27 releases given the even greater emphasis on resizability?
Topic: UI Frameworks SubTopic: SwiftUI
1
1
27
12h
Reordering views in stacks while maintaining structural identity
I'm wondering what the easiest way to reordering a view in a stack is whilst maintaining structural identity, so that it animates/transitions correctly + state is maintained. Ideally if in a LazyVStack it would maintain the laziness too. Think of a stack where if a normal ForEach was used the view may end up being a switch over up to 20 different types of views. I know custom Layouts can be used but they currently cannot be lazy and it seems like a fair bit of work for something that seems fairly simple. Can the below approach be optimised? import SwiftUI struct GroupDemoView: View { @State private var animatesChanges = false @State private var shouldReorder = false private let reorderAnimation = Animation.spring(duration: 3, bounce: 0.5) var body: some View { VStack(spacing: 28) { VStack(spacing: 12) { Toggle("Animate changes", isOn: $animatesChanges) Toggle("Reorder subviews", isOn: animatesChanges ? $shouldReorder.animation(reorderAnimation) : $shouldReorder) } .frame(maxWidth: 240) ScrollView { ReorderingVStack(shouldReorder: shouldReorder) { Text("A") SimpleCard(name: "Card B") Text("B") Text("C") Text("D") Text("E") Text("F") Text("G") Text("H") Text("I") Text("J") Text("K") } } .font(.title3.weight(.semibold)) } .padding() } } private struct ReorderingVStack<Content: View>: View { let shouldReorder: Bool let content: Content init( shouldReorder: Bool, @ViewBuilder content: () -> Content ) { self.shouldReorder = shouldReorder self.content = content() } var body: some View { Group(subviews: content) { subviews in VStack(spacing: 12) { ForEach(rearranged(subviews)) { subview in subview } } } } private func rearranged(_ subviews: SubviewsCollection) -> [Subview] { var subviews = Array(subviews) if shouldReorder { subviews.insert(subviews.remove(at: 1), at: 9) } return subviews } }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
57
12h
Fit Sheet height to view content
In my app I have a sheet that has relatively small content inside. I’d like to fit the height of the sheet to the content of it. As I of course also want to support large type and don’t know how text will break to new lines, I can’t simply set a fixed pixel height. Currently I’m using this trick I saw in some blog post to get it to work. This is the view I’m presenting inside my .sheet: struct SheetContentView: View { @State private var contentHeight: CGFloat = .zero var body: some View { VStack { Text("Foo") Text("Bar") // … } .background( // Required for proper calculation of content height GeometryReader { geo in Color.clear .onChange(of: geo.size.height, initial: true) { _, newValue in contentHeight = newValue } } ) .presentationDetents([.height(contentHeight)]) } } Is this a valid way to do it? What are the best practices to handle this properly or is there even a native way to do this?
Topic: UI Frameworks SubTopic: SwiftUI
2
2
52
12h
List selection binding on iOS
I noticed that on iOS when I tap an already selected List row it calls the selection binding setter again. This is suprising to me because the selection value hasn't changed and results in duplicating unnecessary work to transform the data. Is this behaviour normal or should I report it as a bug? I noticed it when using custom Binding for the selection, i.e. where I implement the get and set closures myself. Thanks!
Topic: UI Frameworks SubTopic: SwiftUI
1
0
13
13h
Recommendation for UI test automation of Swift Packages
I didn't hear any changes to testing in Swift Packages allowing UI tests. Maybe one day. In the meantime what is your recommendation? I see, and have so far chosen to, add an 'example' project inside the package. This is a full fledged app that integrates the package. My next issue is combining the xcresult file of the unit tests of the package, with the ui tests of the example app using the xcresulttool. I don't think it is meant to combine test results from different runs but I could be wrong. I got it working to combine results across different devices and languages of the same test plan but not different ones.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
14
13h
From Mac Catalyst to Mac Native
Previously, the Mac version of my app was built with Mac Catalyst. However, because using the menu bar was inconvenient, I started migrating the Mac version to a native Mac build. Later, I found that starting around macOS 26.4.1, the menu bar that used to appear with my original SwiftUI implementation suddenly stopped showing. As a result, I had to switch back and use an AppKit bridge instead. In addition, I noticed that many visual elements look very strange when built with Mac Catalyst, so I have to adjust each page one by one. I would like to know whether there is a guide for migrating from Mac Catalyst to native Mac, especially regarding style adaptation, so that I can follow the guide and make the necessary changes systematically. Finally, since one of SwiftUI’s advantages is multi-platform deployment, why can’t these styling issues be adapted automatically?
Topic: UI Frameworks SubTopic: SwiftUI
1
1
73
13h
Liquid Glass nav buttons flash
Good morning! Our app uses a dark color scheme regardless of light/dark mode. One issue we’ve had with Liquid Glass has been that buttons in the nav bar do an animation when views are pushed or popped, and the Liquid Glass elements appear to flash during those animations. Are you aware of this behavior? Is there a solution? I suspect that the buttons are mixing in some white even though our background is near black.
Topic: UI Frameworks SubTopic: SwiftUI
3
1
57
13h
Premature Testplan termination since using iPadOS 26.3, Xcode 26.3
Since updating to iPadOS 26.3 and Xcode 26.3, I’ve observed that my testplan suites, that formerly ran 30+ hours and ended with 100% test execution, terminate early at 12-15 hours with an error that suggests an OS-related anomaly is blocking continuation of the test suite. The error in the console is " Wait for accessibility to load" and then a "failure to load accessibility". My tests use the XCUItest framework and accessibility tags to interact with screen elements on the tethered ipad. This never happened on ipadOS 26.2 and earlier. I'm curious if others have seen this behavior and when Apple will get this fixed.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
26
13h
Restricting rotation
My iPhone App has requirement to be locked to portrait, except on certain screens like when showing a video player or other content. What is the best SwiftUI way to do this?
Topic: UI Frameworks SubTopic: SwiftUI
1
1
43
13h
SwiftUI data flow with multiple models that depend on login state
Hi! I’m struggling a bit with data flows in SwiftUI. Most SwiftUI sample apps I’ve seen use one large app model / store and inject that into the environment. That works for small samples, but I’m not sure how this should scale in a real app where the data is naturally split into multiple models/services. For example, I may have separate types for things like: @Observable final class AuthModel { ... } @Observable final class MediaSourcesModel { ... } @Observable final class UsersModel { ... } final class HTTPClient { ... } Some of these only make sense once the user is logged in. For example, media sources, user data, and the HTTP client may all depend on the current user/session/token. What I’m struggling with is where these objects should be owned and created in a SwiftUI app. I’m trying to avoid creating them directly inside a view body, because that can recreate them as the view updates. I’m also unsure whether putting this setup in custom view initializers is the right direction, since SwiftUI views are lightweight and can be reconstructed. What is the recommended ownership / data-flow pattern for this kind of setup? More specifically, how should a SwiftUI app usually handle several separate models that depend on login state, without turning everything into one large global model? Thank you!
Topic: UI Frameworks SubTopic: SwiftUI
1
0
43
13h
SwiftUI navigation transition customization
In the SwiftUI group lab, an engineer mentioned that there were new ways to customize SwiftUI screen transitions. They mentioned there is a crossfade, which I see in the docs, but they also mentioned other customizations. Did they misspeak, or are there custom screen transitions? I'd love a modern, SwiftUI replacement for custom presentation controllers from UIKit!
Topic: UI Frameworks SubTopic: SwiftUI
2
0
80
13h
Tab Bar behavior on resize
Good morning! Not sure this is strictly a SwiftUI question but it is a UI question. The biggest problems we’ve had in adopting the updated UI in recent releases center around the tab bar. We’re an iOS/iPadOS app with a tabbed UI. Having the tab bar arbitrarily jump from the bottom of the screen to the top at a certain size makes laying out our UI very difficult. We’ve worked around this so far by using a custom bar, but that’s clunky and doesn’t work well with Liquid Glass. Are there any changes to this behavior in the 27 releases given the even greater emphasis on resizability?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
1
Boosts
1
Views
27
Activity
12h
Reordering views in stacks while maintaining structural identity
I'm wondering what the easiest way to reordering a view in a stack is whilst maintaining structural identity, so that it animates/transitions correctly + state is maintained. Ideally if in a LazyVStack it would maintain the laziness too. Think of a stack where if a normal ForEach was used the view may end up being a switch over up to 20 different types of views. I know custom Layouts can be used but they currently cannot be lazy and it seems like a fair bit of work for something that seems fairly simple. Can the below approach be optimised? import SwiftUI struct GroupDemoView: View { @State private var animatesChanges = false @State private var shouldReorder = false private let reorderAnimation = Animation.spring(duration: 3, bounce: 0.5) var body: some View { VStack(spacing: 28) { VStack(spacing: 12) { Toggle("Animate changes", isOn: $animatesChanges) Toggle("Reorder subviews", isOn: animatesChanges ? $shouldReorder.animation(reorderAnimation) : $shouldReorder) } .frame(maxWidth: 240) ScrollView { ReorderingVStack(shouldReorder: shouldReorder) { Text("A") SimpleCard(name: "Card B") Text("B") Text("C") Text("D") Text("E") Text("F") Text("G") Text("H") Text("I") Text("J") Text("K") } } .font(.title3.weight(.semibold)) } .padding() } } private struct ReorderingVStack<Content: View>: View { let shouldReorder: Bool let content: Content init( shouldReorder: Bool, @ViewBuilder content: () -> Content ) { self.shouldReorder = shouldReorder self.content = content() } var body: some View { Group(subviews: content) { subviews in VStack(spacing: 12) { ForEach(rearranged(subviews)) { subview in subview } } } } private func rearranged(_ subviews: SubviewsCollection) -> [Subview] { var subviews = Array(subviews) if shouldReorder { subviews.insert(subviews.remove(at: 1), at: 9) } return subviews } }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
2
Boosts
0
Views
57
Activity
12h
Fit Sheet height to view content
In my app I have a sheet that has relatively small content inside. I’d like to fit the height of the sheet to the content of it. As I of course also want to support large type and don’t know how text will break to new lines, I can’t simply set a fixed pixel height. Currently I’m using this trick I saw in some blog post to get it to work. This is the view I’m presenting inside my .sheet: struct SheetContentView: View { @State private var contentHeight: CGFloat = .zero var body: some View { VStack { Text("Foo") Text("Bar") // … } .background( // Required for proper calculation of content height GeometryReader { geo in Color.clear .onChange(of: geo.size.height, initial: true) { _, newValue in contentHeight = newValue } } ) .presentationDetents([.height(contentHeight)]) } } Is this a valid way to do it? What are the best practices to handle this properly or is there even a native way to do this?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
2
Boosts
2
Views
52
Activity
12h
List selection binding on iOS
I noticed that on iOS when I tap an already selected List row it calls the selection binding setter again. This is suprising to me because the selection value hasn't changed and results in duplicating unnecessary work to transform the data. Is this behaviour normal or should I report it as a bug? I noticed it when using custom Binding for the selection, i.e. where I implement the get and set closures myself. Thanks!
Topic: UI Frameworks SubTopic: SwiftUI
Replies
1
Boosts
0
Views
13
Activity
13h
Recommendation for UI test automation of Swift Packages
I didn't hear any changes to testing in Swift Packages allowing UI tests. Maybe one day. In the meantime what is your recommendation? I see, and have so far chosen to, add an 'example' project inside the package. This is a full fledged app that integrates the package. My next issue is combining the xcresult file of the unit tests of the package, with the ui tests of the example app using the xcresulttool. I don't think it is meant to combine test results from different runs but I could be wrong. I got it working to combine results across different devices and languages of the same test plan but not different ones.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
1
Boosts
0
Views
14
Activity
13h
From Mac Catalyst to Mac Native
Previously, the Mac version of my app was built with Mac Catalyst. However, because using the menu bar was inconvenient, I started migrating the Mac version to a native Mac build. Later, I found that starting around macOS 26.4.1, the menu bar that used to appear with my original SwiftUI implementation suddenly stopped showing. As a result, I had to switch back and use an AppKit bridge instead. In addition, I noticed that many visual elements look very strange when built with Mac Catalyst, so I have to adjust each page one by one. I would like to know whether there is a guide for migrating from Mac Catalyst to native Mac, especially regarding style adaptation, so that I can follow the guide and make the necessary changes systematically. Finally, since one of SwiftUI’s advantages is multi-platform deployment, why can’t these styling issues be adapted automatically?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
1
Boosts
1
Views
73
Activity
13h
Liquid Glass nav buttons flash
Good morning! Our app uses a dark color scheme regardless of light/dark mode. One issue we’ve had with Liquid Glass has been that buttons in the nav bar do an animation when views are pushed or popped, and the Liquid Glass elements appear to flash during those animations. Are you aware of this behavior? Is there a solution? I suspect that the buttons are mixing in some white even though our background is near black.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
3
Boosts
1
Views
57
Activity
13h
Premature Testplan termination since using iPadOS 26.3, Xcode 26.3
Since updating to iPadOS 26.3 and Xcode 26.3, I’ve observed that my testplan suites, that formerly ran 30+ hours and ended with 100% test execution, terminate early at 12-15 hours with an error that suggests an OS-related anomaly is blocking continuation of the test suite. The error in the console is " Wait for accessibility to load" and then a "failure to load accessibility". My tests use the XCUItest framework and accessibility tags to interact with screen elements on the tethered ipad. This never happened on ipadOS 26.2 and earlier. I'm curious if others have seen this behavior and when Apple will get this fixed.
Topic: UI Frameworks SubTopic: SwiftUI
Replies
1
Boosts
0
Views
26
Activity
13h
Restricting rotation
My iPhone App has requirement to be locked to portrait, except on certain screens like when showing a video player or other content. What is the best SwiftUI way to do this?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
1
Boosts
1
Views
43
Activity
13h
SwiftUI data flow with multiple models that depend on login state
Hi! I’m struggling a bit with data flows in SwiftUI. Most SwiftUI sample apps I’ve seen use one large app model / store and inject that into the environment. That works for small samples, but I’m not sure how this should scale in a real app where the data is naturally split into multiple models/services. For example, I may have separate types for things like: @Observable final class AuthModel { ... } @Observable final class MediaSourcesModel { ... } @Observable final class UsersModel { ... } final class HTTPClient { ... } Some of these only make sense once the user is logged in. For example, media sources, user data, and the HTTP client may all depend on the current user/session/token. What I’m struggling with is where these objects should be owned and created in a SwiftUI app. I’m trying to avoid creating them directly inside a view body, because that can recreate them as the view updates. I’m also unsure whether putting this setup in custom view initializers is the right direction, since SwiftUI views are lightweight and can be reconstructed. What is the recommended ownership / data-flow pattern for this kind of setup? More specifically, how should a SwiftUI app usually handle several separate models that depend on login state, without turning everything into one large global model? Thank you!
Topic: UI Frameworks SubTopic: SwiftUI
Replies
1
Boosts
0
Views
43
Activity
13h
SwiftUI navigation transition customization
In the SwiftUI group lab, an engineer mentioned that there were new ways to customize SwiftUI screen transitions. They mentioned there is a crossfade, which I see in the docs, but they also mentioned other customizations. Did they misspeak, or are there custom screen transitions? I'd love a modern, SwiftUI replacement for custom presentation controllers from UIKit!
Topic: UI Frameworks SubTopic: SwiftUI
Replies
2
Boosts
0
Views
80
Activity
13h