Search results for

“swiftui”

17,491 results found

Post

Replies

Boosts

Views

Activity

Where does ResearchKit live in the era of Liquid Glass and SwiftUI-first development?
When will ResearchKit get the needed overhaul to be fully compatible with Liquid Glass? CareKit is a SwiftUI first offering with many customization points, but ResearchKit, its older sibling, hasn’t merged the SwiftUI work. I’d like to see SwiftUI, distribution as a Swift Package, and more frequent versioned releases. Can anything be shared on the state of and plans for ResearchKit going forward? It is open source so there isn’t a good way to file feedback other than just sending to the HealthKit team. FB9558499 FB15694524 FB20292373
1
0
436
Jun ’26
Reply to ForEach with calculations between each cell
Hmm, this sounds like something at a data level, which may not be the responsibility of the ForEach. What does your model look like? Traditionally, you could do this with a .reduce on a standard Swift collection, and pass the result into SwiftUI's ForEach. Though I'm not quite sure I understand your question fully. Could you elaborate or show a code example? Thanks :)
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Reply to Making View's init nonisolated with environment variables
The concurrency requirement for a framework like SwiftUI is different than an application. SwiftUI's API has to be compatible with a vast amount of use cases, including apps building in Swift 5 mode, apps using older SDKs where compiler diagnostic with regard to concurrency behaves differently, etc. Nonisolated inits is necessary to maintain source compatibility with all these edge use cases. Unless you are working on a framework that needs to be source/ABI compatible with older compilers, an unknown number of concurrency setting combinations, etc (in which case, bravo!), you really shouldn't have the burden of maintaining nonisolated initializers. It's a little surprising that you need to dependency inject a view. Usually dependency injection deals with data flow. I'd consider using other method to perhaps modularize your view code. For example, if your view isn't changing frequently, you can remove dependencies between views using AnyView.
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Is a volumetric window recommended for menus in 3D-focused visionOS apps?
For a visionOS app whose main content is 3D, such as a game or immersive experience, is it recommended to use a volumetric window as the main menu or in-game menu? I’d like to understand the intended use cases for menus built as volumetric windows. Specifically: What are the advantages of using a volumetric window for menu UI compared with a regular 2D window or an in-scene SwiftUI attachment? What limitations should developers be aware of, such as fixed size, placement behavior, lighting separation, interaction comfort, or window management? For a 3D game-like app, is a volumetric menu generally considered a good visionOS design pattern, or should volumetric windows be reserved for 3D content rather than menu-heavy UI? Any guidance on the recommended design approach would be appreciated.
4
0
473
Jun ’26
Reply to Improving List performance with DisclosureGroup in large data sets
We've made improvements specifically for the performance of DisclosureGroup inside of List in macOS 27.0. Wow! That’s great to hear! Thank you for making those improvements. Lists and tables are still areas where SwiftUI can be challenging to use on macOS, so I always look forward to the performance improvements and API refinements that arrive each year. In that case, my scenario may provide a useful test case. I’ll put together a detailed report and submit it through Feedback Assistant.
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Updates on Storyboards
In the past few years, there hasn't been much updates around Storyboards and yet it seems like Xcode supports them. Even before the first release of SwiftUI, many developers stopped using Storyboards for compelling reasons such as: They introduce two sources of truth for the UI It's not easy to read the content during code-review They can cause merge conflicts Often they fail to load, especially after a new major release of Xcode, without any error I was wondering whether there's a dedicated team working on Storyboards or if they're just abandoned. I understand this question may overlap with what the Xcode team does; so, let me rephrase it: in a large project, what are the pros and cons of using Storyboards when building views using UIKit? For instance, do they work well with things such as navigation by employing segues, the liquid glass or the new resizing feature? Finally, one of the benefits of using Storyboards is the fact that they visualize the UI, including the constraints. However, since now
Topic: UI Frameworks SubTopic: UIKit
1
0
299
Jun ’26
Reply to Fit Sheet height to view content
This is a perfectly good pattern to have your sheet set to the custom detent of the height of the view it contains. This can get tricky with ScrollViews in sheets in which case you need to measure the size of the view inside the ScrollView since the ScrollView itself doesn't have a preferred size when it's height proposal is nil. For slightly better performance you can use on geometry change instead: import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var showingSheet = false @State private var swatchHeight: CGFloat = 100 @State private var measuredSheetHeight: CGFloat = 100 @State private var selectedDetent: PresentationDetent = .height(100) var body: some View { Button(Show Sheet) { showingSheet = true } .sheet(isPresented: $showingSheet) { AutoSizingSheet( swatchHeight: $swatchHeight, measuredSheetHeight: $measuredSheetHeight, selectedDetent: $selectedDetent ) } } } private struct AutoSizingSheet: View { @Bindi
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Reply to Performance considerations using ViewThatFits
The performance considerations really depend on your specific use case, especially if the views you're asking ViewThatFits to choose between are complex, since you're effectively initializing and measuring each candidate view and all of its children, and this happens on every layout pass. For resizability, the best way to react to changes in size is by tracking size class changes for overall window size, or onGeometryChange for tracking the size of individual views. The nice thing about this is that it gives you more control over the thresholds at which the decision of which view to display happens. Instead of making a conditional view decision on every frame of a resize action, you could try defining break points for your layout. For instance, you might code up some logic where when the parent view's width moves between certain ranges, you set a state variable that specifies which view to show. onGeometryChange's action closure only fires when the value returned by its transform closure changes, so this allo
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Reply to List selection binding on iOS
You don't have to transform the data if you know the selected item is being selected again. SwiftUI must support all use cases, and some use cases demand that the binding gets called over and over again!
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Reply to Making View's init nonisolated with environment variables
Great question! In SwiftUI, we have made it as easy as possible to use it in the Swift 6 language mode. You should not need to define your custom Views initializers as nonisolated, because the expectation is that they will be initialized from the parent view's isolation context, and View protocol is @MainActor in SwiftUI. This means that there is really no reason for your view to be initialized from a nonisolated context, since the context will be main-actor-isolated anyway. Great observation that SwiftUI's own custom Views have their initializer marked as nonisolated. This is a pattern that lets us have more flexibility internally in the framework, but in terms of API, we rely on the fact that these views will be automatically isolated to the @MainActor when used in View.body. While this is a pattern we use internally, it is not needed to replicate for your own custom components. I hope this answers your question! If not, we'd love to see the sample code where it is tricky to avoid
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Custom PinnedScrollableViews
In a simple scenario, it's possible to have a ScrollView that contains a LazyVStack where the headers or footers of Section gets pinned to the top safe area. In a more complicated scenario, where The ScrollView needs to ignore the top safe area The navigation bar is hidden until a certain view, call it Foo, has gone behind what used to be the top safe area, i.e., only about 100p of the view is visible which would be invisible if the navigation bar wasn't transparent/hidden. The navigation bar becomes visible once Foo is scrolled up to a threshold that was explained earlier A second view, call is Bar, that's positioned below Foo, should never go behind the navigation bar, i.e., it should be pinned to the bottom of the navigation bar I managed to achieve this behaviour by having a State for the ignored safe area edges that gets updated based on how far Foo is scrolled. However, I get a jumpy behaviour because the ScrollView tries to adjust its contentOffset/contentInset based on the new top safe area. This jump
Topic: UI Frameworks SubTopic: SwiftUI
4
0
211
Jun ’26
Making View's init nonisolated with environment variables
Views with custom nonisolated init fail to compile when using @MainActor-isolated @Environment properties (e.g., .openURL, .dismiss). From the Swift 6 migration documentation, it seems encouraged to define inits nonisolated, and it seems base SwiftUI components also have their inits defined as nonisolated (e.g. TimelineView, LazyHStack, etc), which makes sense. How do you achieve marking a SwiftUI View's init as nonisolated when it uses environment variables, without producing the following build error Main actor-isolated default value of 'self.openURL' cannot be used in a nonisolated initalizer ? It seems @State variable defined in a view has the ability to be set in a nonisolated init but not @Environment. What mechanism prevents this under the hood ?
Topic: UI Frameworks SubTopic: SwiftUI
7
0
272
Jun ’26
Reply to Restricting rotation
In iOS 27, iPhone apps can now be resized for iPhone Mirroring, or when running on an iPad. SwiftUI makes it really easy to support resizability by leveraging size classes and more, and you can learn more about resizability from What’s New in SwiftUI. We encourage you to reconsider the requirement and design the app for all Apple devices, meeting customers where they are.
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
Reply to Premature Testplan termination since using iPadOS 26.3, Xcode 26.3
Hello @ADietz, Thank you for contributing to the Developer Forums This Q&A is about SwiftUI, if you have a question about SwiftUI, we have engineers available to answer your questions! For testing questions, please create a separate post in the Forums and it will receive better proper attention there!  Travis
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Jun ’26
How to avoid trailing toolbar item re-rendering on child navigation
I have a NavigationStack where every child view except the root has a trailing close button. On each child view transition, the button re-renders itself. Is there a way to fix the button? I saw in the Apple Developer app the behavior I want when registering a lab and the confirmation screen, but I think the implementation is just changing the center content of the view and it isn't pushing a new view to the stack path that has different toolbar items. Root: VStack { Content Next button --> Page 2 } Cancel button leading edge Page 2: VStack { Copy Next button --> page 3 } built in back button leading edge cancel button trailing edge Page 3: VStack { Copy Finish button --> dismisses whole workflow } built in back button leading edge cancel button trailing edge So on page 3, the cancel button is new. I can't figure out how to not have the glass effect animate it in new. I want the 'same' cancel button to be there. This is an oversimplification of a resumable form where the user can cancel (save and resu
Topic: UI Frameworks SubTopic: SwiftUI
2
0
223
Jun ’26
Where does ResearchKit live in the era of Liquid Glass and SwiftUI-first development?
When will ResearchKit get the needed overhaul to be fully compatible with Liquid Glass? CareKit is a SwiftUI first offering with many customization points, but ResearchKit, its older sibling, hasn’t merged the SwiftUI work. I’d like to see SwiftUI, distribution as a Swift Package, and more frequent versioned releases. Can anything be shared on the state of and plans for ResearchKit going forward? It is open source so there isn’t a good way to file feedback other than just sending to the HealthKit team. FB9558499 FB15694524 FB20292373
Replies
1
Boosts
0
Views
436
Activity
Jun ’26
Reply to ForEach with calculations between each cell
Hmm, this sounds like something at a data level, which may not be the responsibility of the ForEach. What does your model look like? Traditionally, you could do this with a .reduce on a standard Swift collection, and pass the result into SwiftUI's ForEach. Though I'm not quite sure I understand your question fully. Could you elaborate or show a code example? Thanks :)
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Reply to Making View's init nonisolated with environment variables
The concurrency requirement for a framework like SwiftUI is different than an application. SwiftUI's API has to be compatible with a vast amount of use cases, including apps building in Swift 5 mode, apps using older SDKs where compiler diagnostic with regard to concurrency behaves differently, etc. Nonisolated inits is necessary to maintain source compatibility with all these edge use cases. Unless you are working on a framework that needs to be source/ABI compatible with older compilers, an unknown number of concurrency setting combinations, etc (in which case, bravo!), you really shouldn't have the burden of maintaining nonisolated initializers. It's a little surprising that you need to dependency inject a view. Usually dependency injection deals with data flow. I'd consider using other method to perhaps modularize your view code. For example, if your view isn't changing frequently, you can remove dependencies between views using AnyView.
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Is a volumetric window recommended for menus in 3D-focused visionOS apps?
For a visionOS app whose main content is 3D, such as a game or immersive experience, is it recommended to use a volumetric window as the main menu or in-game menu? I’d like to understand the intended use cases for menus built as volumetric windows. Specifically: What are the advantages of using a volumetric window for menu UI compared with a regular 2D window or an in-scene SwiftUI attachment? What limitations should developers be aware of, such as fixed size, placement behavior, lighting separation, interaction comfort, or window management? For a 3D game-like app, is a volumetric menu generally considered a good visionOS design pattern, or should volumetric windows be reserved for 3D content rather than menu-heavy UI? Any guidance on the recommended design approach would be appreciated.
Replies
4
Boosts
0
Views
473
Activity
Jun ’26
Reply to Improving List performance with DisclosureGroup in large data sets
We've made improvements specifically for the performance of DisclosureGroup inside of List in macOS 27.0. Wow! That’s great to hear! Thank you for making those improvements. Lists and tables are still areas where SwiftUI can be challenging to use on macOS, so I always look forward to the performance improvements and API refinements that arrive each year. In that case, my scenario may provide a useful test case. I’ll put together a detailed report and submit it through Feedback Assistant.
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Updates on Storyboards
In the past few years, there hasn't been much updates around Storyboards and yet it seems like Xcode supports them. Even before the first release of SwiftUI, many developers stopped using Storyboards for compelling reasons such as: They introduce two sources of truth for the UI It's not easy to read the content during code-review They can cause merge conflicts Often they fail to load, especially after a new major release of Xcode, without any error I was wondering whether there's a dedicated team working on Storyboards or if they're just abandoned. I understand this question may overlap with what the Xcode team does; so, let me rephrase it: in a large project, what are the pros and cons of using Storyboards when building views using UIKit? For instance, do they work well with things such as navigation by employing segues, the liquid glass or the new resizing feature? Finally, one of the benefits of using Storyboards is the fact that they visualize the UI, including the constraints. However, since now
Topic: UI Frameworks SubTopic: UIKit
Replies
1
Boosts
0
Views
299
Activity
Jun ’26
Reply to Fit Sheet height to view content
This is a perfectly good pattern to have your sheet set to the custom detent of the height of the view it contains. This can get tricky with ScrollViews in sheets in which case you need to measure the size of the view inside the ScrollView since the ScrollView itself doesn't have a preferred size when it's height proposal is nil. For slightly better performance you can use on geometry change instead: import SwiftUI @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct ContentView: View { @State private var showingSheet = false @State private var swatchHeight: CGFloat = 100 @State private var measuredSheetHeight: CGFloat = 100 @State private var selectedDetent: PresentationDetent = .height(100) var body: some View { Button(Show Sheet) { showingSheet = true } .sheet(isPresented: $showingSheet) { AutoSizingSheet( swatchHeight: $swatchHeight, measuredSheetHeight: $measuredSheetHeight, selectedDetent: $selectedDetent ) } } } private struct AutoSizingSheet: View { @Bindi
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Reply to Performance considerations using ViewThatFits
The performance considerations really depend on your specific use case, especially if the views you're asking ViewThatFits to choose between are complex, since you're effectively initializing and measuring each candidate view and all of its children, and this happens on every layout pass. For resizability, the best way to react to changes in size is by tracking size class changes for overall window size, or onGeometryChange for tracking the size of individual views. The nice thing about this is that it gives you more control over the thresholds at which the decision of which view to display happens. Instead of making a conditional view decision on every frame of a resize action, you could try defining break points for your layout. For instance, you might code up some logic where when the parent view's width moves between certain ranges, you set a state variable that specifies which view to show. onGeometryChange's action closure only fires when the value returned by its transform closure changes, so this allo
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Reply to List selection binding on iOS
You don't have to transform the data if you know the selected item is being selected again. SwiftUI must support all use cases, and some use cases demand that the binding gets called over and over again!
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Reply to Making View's init nonisolated with environment variables
Great question! In SwiftUI, we have made it as easy as possible to use it in the Swift 6 language mode. You should not need to define your custom Views initializers as nonisolated, because the expectation is that they will be initialized from the parent view's isolation context, and View protocol is @MainActor in SwiftUI. This means that there is really no reason for your view to be initialized from a nonisolated context, since the context will be main-actor-isolated anyway. Great observation that SwiftUI's own custom Views have their initializer marked as nonisolated. This is a pattern that lets us have more flexibility internally in the framework, but in terms of API, we rely on the fact that these views will be automatically isolated to the @MainActor when used in View.body. While this is a pattern we use internally, it is not needed to replicate for your own custom components. I hope this answers your question! If not, we'd love to see the sample code where it is tricky to avoid
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Custom PinnedScrollableViews
In a simple scenario, it's possible to have a ScrollView that contains a LazyVStack where the headers or footers of Section gets pinned to the top safe area. In a more complicated scenario, where The ScrollView needs to ignore the top safe area The navigation bar is hidden until a certain view, call it Foo, has gone behind what used to be the top safe area, i.e., only about 100p of the view is visible which would be invisible if the navigation bar wasn't transparent/hidden. The navigation bar becomes visible once Foo is scrolled up to a threshold that was explained earlier A second view, call is Bar, that's positioned below Foo, should never go behind the navigation bar, i.e., it should be pinned to the bottom of the navigation bar I managed to achieve this behaviour by having a State for the ignored safe area edges that gets updated based on how far Foo is scrolled. However, I get a jumpy behaviour because the ScrollView tries to adjust its contentOffset/contentInset based on the new top safe area. This jump
Topic: UI Frameworks SubTopic: SwiftUI
Replies
4
Boosts
0
Views
211
Activity
Jun ’26
Making View's init nonisolated with environment variables
Views with custom nonisolated init fail to compile when using @MainActor-isolated @Environment properties (e.g., .openURL, .dismiss). From the Swift 6 migration documentation, it seems encouraged to define inits nonisolated, and it seems base SwiftUI components also have their inits defined as nonisolated (e.g. TimelineView, LazyHStack, etc), which makes sense. How do you achieve marking a SwiftUI View's init as nonisolated when it uses environment variables, without producing the following build error Main actor-isolated default value of 'self.openURL' cannot be used in a nonisolated initalizer ? It seems @State variable defined in a view has the ability to be set in a nonisolated init but not @Environment. What mechanism prevents this under the hood ?
Topic: UI Frameworks SubTopic: SwiftUI
Replies
7
Boosts
0
Views
272
Activity
Jun ’26
Reply to Restricting rotation
In iOS 27, iPhone apps can now be resized for iPhone Mirroring, or when running on an iPad. SwiftUI makes it really easy to support resizability by leveraging size classes and more, and you can learn more about resizability from What’s New in SwiftUI. We encourage you to reconsider the requirement and design the app for all Apple devices, meeting customers where they are.
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
Reply to Premature Testplan termination since using iPadOS 26.3, Xcode 26.3
Hello @ADietz, Thank you for contributing to the Developer Forums This Q&A is about SwiftUI, if you have a question about SwiftUI, we have engineers available to answer your questions! For testing questions, please create a separate post in the Forums and it will receive better proper attention there!  Travis
Topic: SwiftUI SubTopic:
SwiftUI Q&A
Replies
Boosts
Views
Activity
Jun ’26
How to avoid trailing toolbar item re-rendering on child navigation
I have a NavigationStack where every child view except the root has a trailing close button. On each child view transition, the button re-renders itself. Is there a way to fix the button? I saw in the Apple Developer app the behavior I want when registering a lab and the confirmation screen, but I think the implementation is just changing the center content of the view and it isn't pushing a new view to the stack path that has different toolbar items. Root: VStack { Content Next button --> Page 2 } Cancel button leading edge Page 2: VStack { Copy Next button --> page 3 } built in back button leading edge cancel button trailing edge Page 3: VStack { Copy Finish button --> dismisses whole workflow } built in back button leading edge cancel button trailing edge So on page 3, the cancel button is new. I can't figure out how to not have the glass effect animate it in new. I want the 'same' cancel button to be there. This is an oversimplification of a resumable form where the user can cancel (save and resu
Topic: UI Frameworks SubTopic: SwiftUI
Replies
2
Boosts
0
Views
223
Activity
Jun ’26