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

SwiftUI Documentation

Posts under SwiftUI subtopic

Post

Replies

Boosts

Views

Activity

A Summary of the WWDC25 Group Lab - SwiftUI
At WWDC25 we launched a new type of Lab event for the developer community - Group Labs. A Group Lab is a panel Q&A designed for a large audience of developers. Group Labs are a unique opportunity for the community to submit questions directly to a panel of Apple engineers and designers. Here are the highlights from the WWDC25 Group Lab for SwiftUI. What's your favorite new feature introduced to SwiftUI this year? The new rich text editor, a collaborative effort across multiple Apple teams. The safe area bar, simplifying the management of scroll view insets, safe areas, and overlays. NavigationLink indicator visibility control, a highly requested feature now available and back-deployed. Performance improvements to existing components (lists, scroll views, etc.) that come "for free" without requiring API adoption. Regarding performance profiling, it's recommended to use the new SwiftUI Instruments tool when you have a good understanding of your code and notice a performance drop after a specific change. This helps build a mental map between your code and the profiler's output. The "cause-and-effect graph" in the tool is particularly useful for identifying what's triggering expensive view updates, even if the issue isn't immediately apparent in your own code. My app is primarily UIKit-based, but I'm interested in adopting some newer SwiftUI-only scene types like MenuBarExtra or using SwiftUI-exclusive features. Is there a better way to bridge these worlds now? Yes, "scene bridging" makes it possible to use SwiftUI scenes from UIKit or AppKit lifecycle apps. This allows you to display purely SwiftUI scenes from your existing UIKit/AppKit code. Furthermore, you can use SwiftUI scene-specific modifiers to affect those scenes. Scene bridging is a great way to introduce SwiftUI into your apps. This also allows UIKit apps brought to Vision OS to integrate volumes and immersive spaces. It's also a great way to customize your experience with Assistive Access API. Can you please share any bad practices we should avoid when integrating Liquid Glass in our SwiftUI Apps? Avoid these common mistakes when integrating liquid glass: Overlapping Glass: Don't overlap liquid glass elements, as this can create visual artifacts. Scrolling Content Collisions: Be cautious when using liquid glass within scrolling content to prevent collisions with toolbar and navigation bar glass. Unnecessary Tinting: Resist the urge to tint the glass for branding or other purposes. Liquid glass should primarily be used to draw attention and convey meaning. Improper Grouping: Use the GlassEffectContainer to group related glass elements. This helps the system optimize rendering by limiting the search area for glass interactions. Navigation Bar Tinting: Avoid tinting navigation bars for branding, as this conflicts with the liquid glass effect. Instead, move branding colors into the content of the scroll view. This allows the color to be visible behind the glass at the top of the view, but it moves out of the way as the user scrolls, allowing the controls to revert to their standard monochrome style for better readability. Thanks for improving the performance of SwiftUI List this year. How about LazyVStack in ScrollView? Does it now also reuse the views inside the stack? Are there any best practices for improving the performance when using LazyVStack with large number of items? SwiftUI has improved scroll performance, including idle prefetching. When using LazyVStack with a large number of items, ensure your ForEach returns a static number of views. If you're returning multiple views within the ForEach, wrap them in a VStack to signal to SwiftUI that it's a single row, allowing for optimizations. Reuse is handled as an implementation detail within SwiftUI. Use the performance instrument to identify expensive views and determine how to optimize your app. If you encounter performance issues or hitches in scrolling, use the new SwiftUI Instruments tool to diagnose the problem. Implementing the new iOS 26 tab bar seems to have very low contrast when darker content is underneath, is there anything we should be doing to increase the contrast for tab bars? The new design is still in beta. If you're experiencing low contrast issues, especially with darker content underneath, please file feedback. It's generally not recommended to modify standard system components. As all apps on the platform are adopting liquid glass, feedback is crucial for tuning the experience based on a wider range of apps. Early feedback, especially regarding contrast and accessibility, is valuable for improving the system for all users. If I’m starting a new multi-platform app (iOS/iPadOS/macOS) that will heavily depend on UIKit/AppKit for the core structure and components (split, collection, table, and outline views), should I still use SwiftUI to manage the app lifecycle? Why? Even if your new multi-platform app heavily relies on UIKit/AppKit for core structure and components, it's generally recommended to still use SwiftUI to manage the app lifecycle. This sets you up for easier integration of SwiftUI components in the future and allows you to quickly adopt new SwiftUI features. Interoperability between SwiftUI and UIKit/AppKit is a core principle, with APIs to facilitate going back and forth between the two frameworks. Scene bridging allows you to bring existing SwiftUI scenes into apps that use a UIKit lifecycle, or vice versa. Think of it not as a binary choice, but as a mix of whatever you need. I’d love to know more about the matchedTransitionSource API you’ve added - is it a native way to have elements morph from a VStack to a sheet for example? What is the use case for it? The matchedTransitionSource API helps connect different views during transitions, such as when presenting popovers or other presentations from toolbar items. It's a way to link the user interaction to the presented content. For example, it can be used to visually connect an element in a VStack to a sheet. It can also be used to create a zoom effect where an element appears to enlarge, and these transitions are fully interactive, allowing users to swipe. It creates a nice, polished experience for the user. Support for this API has been added to toolbar items this year, and it was already available for standard views.
Topic: UI Frameworks SubTopic: SwiftUI
1
0
950
Jun ’25
Swift UI on iOS 14 not assigning new object to @State property
On iOS 13 I used to use optional @State properties to adapt views. In my case, the presented view would either create a new object (an assignment) if the state that is passed into it is nil, or edit the assignment if an assignment was passed in. This would be done in the action block of a Button and it worked beautifully. On iOS 14 / Xcode 12 this no longer seems to work. Given the following code which creates a new assignment and passes it into the editor view when the user taps a "New Assignment" button, the value of assignment remains nil. Is anyone else experiencing similar behaviour? struct ContentView: View { 		@Environment(\.managedObjectContext) var context 		@State var assignmentEditorIsPresented = false 		@State var assignment: Assignment? = nil 		var Body: some View { 				[...] 				Button("New Assignment", action: { 						self.assignment = Assignment(context: context) 						self.assignmentEditorIsPresented = true 				}) 				.sheet(isPresented: assignmentEditorIsPresented) { 						[...] 				} 		} } What's even weirder is that I tried adding a random piece of state, an Int, to this view and modifying it right before the assignment state (between lines 9 and 10) and it didn't change either.
21
4
13k
Mar ’25
List View Drag&Drop Support on iOS
Hi there, Upon using List View for tabular information showcase on both iOS and iPadOS, I have come to realize that the drag and drop support works only for iPadOS but not iOS. Although it is possible to workaround this by using a ScrollView wrapping around a LazyVStack instead, the editing mode along with left-wipe to delete feature would be missing. Not to mention that this workaround only supports single item rather than multiple items. Therefore, I am here to ask if the drag and drop will come to support devices running iOS, and if so, when will this feature ship. If not, will LazyVStack/LazyHStack support native editing mode. Thank you for your time.
1
2
361
Oct ’25
Lock widget for pro-users
Hi, I have added widgets to my iOS app and I would like to make this feature only accessible to "pro" users that have made a non-consumable in-app purchase. Currently, I am doing the following: I store an "isUnlocked" property in the Keychain after the purchase is made I read data to be displayed in the widget and here I also query the Keychain and store whether the widget is unlocked I have no refresh policy, but only change the widget data on a significant time change a different view is displayed when the app is locked Some dummy code snippets: func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) { &#9;&#9;let entry = readContents() &#9;&#9;let timeline = Timeline(entries: [entry], policy: .never) &#9;&#9;completion(timeline) } struct WidgetEntryView: View { &#9;&#9;let entry: Provider.Entry     @Environment(\.widgetFamily) var family     @ViewBuilder     var body: some View {         switch family {         case .systemSmall:             if !entry.isUnlocked {                 LockedWidgetView()             } else if let event = entry.event {                 SmallWidgetEventView(event: event)             } else {                 NoDataWidgetView()             } ... func applicationSignificantTimeChange(_ application: UIApplication) { &#9;&#9;if #available(iOS 14.0, *) { &#9;&#9;&#9;&#9;WidgetCenter.shared.reloadAllTimelines() &#9;&#9;} ... However, 2 unexpected things happen: the view is refreshed intraday (not only at midnight i.e. at significant time change) sometimes the LockedWidgetView is displayed. Especially the latter is problematic, because it gives false information to a user that has already made the in-app purchase. How can I achieve my goal of only displaying info when the user has made the in-app purchase? Thanks in advance. P.S. Although it would not have my preference, I would also find it acceptable if the widget is only shown as option to add once the purchase is made. In other words, I was considering changing the Widget itself: struct MyWidget: Widget {     private var supportedFamilies: [WidgetFamily] = isUnlocked() ? [.systemSmall, .systemMedium] : [] but I believe I cannot re-initialise the widget from the app when the user makes the in-app purchase, because the only refresh option that I have is WidgetCenter.shared.reloadAllTimelines()
7
0
3.6k
May ’25
ScrollView won't scroll
Hello. I have successfully created a scrollview with several buttons that stack on top of one another. But the View won't scroll. What am i doing wrong here? scrollView = UIScrollView.init(frame: CGRect.zero) &#9;&#9;&#9;&#9;scrollView.translatesAutoresizingMaskIntoConstraints = false &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;self.view.addSubview(scrollView) &#9;&#9;&#9;&#9;var leadingAnchor = self.scrollView!.topAnchor &#9;&#9;&#9;&#9;for i in 0..<20{ &#9;&#9;&#9;&#9;&#9;&#9;let t_button = UIButton.init(frame: CGRect.zero) &#9;&#9;&#9;&#9;&#9;&#9;t_button.translatesAutoresizingMaskIntoConstraints = false &#9;&#9;&#9;&#9;&#9;&#9;t_button.backgroundColor = UIColor.blue &#9;&#9;&#9;&#9;&#9;&#9;scrollView.addSubview(t_button) &#9;&#9;&#9;&#9;&#9;&#9;NSLayoutConstraint.activate([ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;t_button.topAnchor.constraint(equalTo: leadingAnchor, constant:5.0), &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;t_button.centerXAnchor.constraint(equalTo: scrollView.centerXAnchor), &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;t_button.heightAnchor.constraint(equalToConstant: 50.0), &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;t_button.widthAnchor.constraint(equalToConstant: 75.0) &#9;&#9;&#9;&#9;&#9;&#9;]) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;leadingAnchor = t_button.bottomAnchor &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;t_button.setTitle("Button \(i)", for: .normal) &#9;&#9;&#9;&#9;&#9;&#9;t_button.addTarget(self, action: #selector(scrollViewButtonAction(_:)), for: .touchUpInside) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;NSLayoutConstraint.activate([ &#9;&#9;&#9;&#9;&#9;&#9;scrollView.topAnchor.constraint(equalTo: self.titleHeader.bottomAnchor, constant: 10.0), &#9;&#9;&#9;&#9;&#9;&#9;scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), &#9;&#9;&#9;&#9;&#9;&#9;scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor), &#9;&#9;&#9;&#9;&#9;&#9;scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor), &#9;&#9;&#9;&#9;])
4
0
7.5k
Mar ’25
View with FetchRequest doesnt update on change
Hello guys, this is my first post to this forum and really hope that somebody can help me here. I would highly appreciate every help! I am writing my first app with Swift UI (never used UIKit before) which I want to publish later on. This is also my first app which has CoreData implemented. For example I use the following entities: Family, Person 1 Persons can have 1 Family 1 Family can have many Persons My App is structured as the following: ContentView: Contains a TabView with 2 other views in it. A Settings View and a View with a LazyVGrid. LazyVGrid View: This View shows a GridItem for every Family. I get the Families with the following Fetchrequest: @Environment(\.managedObjectContext) private var viewContext // These are the Families from the FetchRequest @FetchRequest(entity: Family.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Family.created, ascending: false)] ) var families: FetchedResults<Family> Every GridItem is linking to a "FamilyDetailView" via NavigationLink. So i pass the family as the following: NavigationLink(destination: FamilyDetailView(family: family).environment(\.managedObjectContext, self.viewContext), label: {Text("Family Name") In the FamilyDetailView i get the Family with a property wrapper: @State var family : Family In this FamilyDetailView is the problem i have. Here I also have a LazyVGrid, which shows 1 NavigationLink for every Person in the Family in a GridItem . In this GridItem I also show for example the "name" of the Person. When tapping the NavigationLink i get to the last View, the PersonDetailView. This View gets the Person which is also an entity which has a relationship to the Family Entity. I pass it as the follow: NavigationLink( destination: PersonDetailView(person: person), label: {Text("Person")}) In the PersonDetailView I now change the name of the person and save the changed to CoreData. The change is saved without a problem, the problem is that when I go back, using the topleading back button from the NavigationView, the Views are not updated. I have to restart the App to see the changes.. I know that the Problem has to be with passing the Data, but I cant figuring out what I did wrong. I really appreciate everyone trying to help me! Thank you very very much!!
1
1
756
Sep ’25
LazyVGrid (embedded in a List) does not resize automatically when content increases and layout changes
I have a List in a sidebar style which contains a LazyVGrid and a Section with a simple list contents. Every thing works well except when content increases and layout changes (from two columns to one column) for the LazyVGrid with editMode changing to .active ... LazyVGrid does not expand/resize when the content increases (the increased content gets clipped)...but does when user expands/folds on the section below :(. However LazyVGrid resizes to show the entire content when the content shrinks with editMode reverting to .inactive Note: If I replace the List with a ScrollView...lazyVGrid resizes perfectly when content increases in editMode = .active....but then I would lose all the Sidebar and List characteristics for the Section below :( Also, looks like .onMove is not supported in LazyVGrids Any pointers to solve the LazyVGrid (embedded in a List) not resizing or expanding when content increases ... will be deeply appreciated. var body: some View {         List {             LazyVGrid(columns: editMode?.wrappedValue == .active ? singleColumn : twoColumns, alignment: .leading, spacing: 10) {                 ForEach(editMode?.wrappedValue == .active ? allDashItems : selectedDashItems) { dashitem in                     DashItemCell(dashitem)                                         }                 .onMove(perform: moveDashItem)                 .environment(\.editMode, editMode)             }             Section(header: Text("Bottom Section")) {                     ForEach (sectionList)&#9;{ item in                         ListItemCell(item)                     }                     .onDelete(perform: deleteFolder)                     .onMove(perform: moveFolder)                 }         }         .listStyle(SidebarListStyle()) }
1
1
1.7k
May ’25
Setting launch screen image through info.plist - image stretches to cover full screen
I am developing an app in swiftUI using Xcode 12.3, deployment target iOS 14.0. The launch screen is setup through info.plist by specifying 'background color' and 'image name'. The file used in 'image name' is from Assets catalog. (PNG format, size300 x 300 and corresponding @2x and @3x resolutions) What I have observed, when the app is installed for the first time the launch image is centered and have original resolutions but all subsequent launches show launch images stretched to cover full screen. Any ideas why this is happening and how to have more consistent behavior either way? I have tried 'respect safe area' option but it does not make a difference. Thank you.
12
2
13k
Mar ’25
How do I pass a binding to a focus state?
In a SwiftUI lab, I was asking about setting the focus state down a view hierarchy. The answer I got was to pass the focus state down the views as a binding. Conceptually, that made sense, so I moved on to other questions. But now that I am trying to implement it, I am having problems. In the parent view, I have something like this: @FocusState private var focusElement: UUID? Then I am setting a property like this in the child view: @Binding var focusedId: UUID? When I try to create the detail view, I'm trying this: DetailView(focusedId: $focusElement) But this doesn't work. The error I get is: Cannot convert value of type 'FocusState<UUID?>.Binding' to expected argument type 'Binding<UUID?>' What is the right way to pass down the focus state to a child view so that it can update back up to the parent view? I am trying to update from one child view, and have a TextField in a sibling view get focus.
2
0
13k
Jan ’25
AsyncImage - Cancelled Loading before View is Visible
I have been playing around with the new AsyncImage Api in SwiftUI I am using the initialiser that passes in a closure with the AsyncImagePhase, to view why an image may not load, when I looked at the error that is passed in if the phase is failure, the localised description of the error is "Cancelled" but this is happening before the view is being displayed. I am loading these images in a list, I imagine I am probably doing something which is causing the system to decide to cancel the loading, but I cannot see what. Are there any tips to investigate this further?
15
8
13k
Feb ’25
Accessing an actor's isolated state from within a SwiftUI view
I'm trying to understand a design pattern for accessing the isolated state held in an actor type from within a SwiftUI view. Take this naive code: actor Model: ObservableObject { @Published var num: Int = 0 func updateNumber(_ newNum: Int) { self.num = newNum } } struct ContentView: View { @StateObject var model = Model() var body: some View { Text("\(model.num)") // <-- Compiler error: Actor-isolated property 'num' can not be referenced from the main actor Button("Update number") { Task.detached() { await model.updateNumber(1) } } } } Understandably I get the compiler error Actor-isolated property 'num' can not be referenced from the main actor when I try and access the isolated value. Yet I can't understand how to display this data in a view. I wonder if I need a ViewModel that observes the actor, and updates itself on the main thread, but get compile time error Actor-isolated property '$num' can not be referenced from a non-isolated context. class ViewModel: ObservableObject { let model: Model @Published var num: Int let cancellable: AnyCancellable init() { let model = Model() self.model = model self.num = 0 self.cancellable = model.$num // <-- compile time error `Actor-isolated property '$num' can not be referenced from a non-isolated context` .receive(on: DispatchQueue.main) .sink { self.num = $0 } } } Secondly, imagine if this code did compile, then I would get another error when clicking the button that the interface is not being updated on the main thread...again I'm not sure how to effect this from within the actor?
3
2
9.7k
Apr ’25
How to use iOS15-specific modifiers in SwiftUI on iOS 14 and earlier?
There are many new iOS15-specific modifiers that were added in SwiftUI. For example, we have a .focused() modifier, which can be used like this: TextField("Username", text: $username) .focused($focusedField, equals: .username) However, this code fails to compile if the app supports iOS 14 and earlier. How can I make this code to compile? Ideally, I'd like to do something like this: TextField("Username", text: $username) #if os(iOS, 15.0, *) .focused($focusedField, equals: .username) #endif But obviously this won't work because #if os() can only specify the target OS, not the version.. Thanks!
3
0
5.9k
Sep ’25
Contents of .sheet() are being redrawn after dismiss and not presenting
Use Case If you have a ContentView that displays a pausable view based on a @State private var presentSheet = false property that is also used to present a .sheet(isPresented: $presentSheet) if: the property is sent to the PausableView(isPaused: presentSheet) as a normal property, the body of the ContentView and the body of the sheet is being redrawn when the sheet is dismissed the property is sent to the PausableView(isPaused: $presentSheet) as a @Binding, the body of the ContentView and the body of the sheet is NOT redrawn when the sheet is dismissed Is this normal behavior? The ContentView body makes sense to change, but is the sheet's body also supposed to be redrawn when the sheet is not presenting anymore after dismiss? Sample Project A sample project created in Xcode 13 is available here: https://github.com/clns/SwiftUI-sheet-redraw-on-dismiss. I noticed the same behavior on iOS 14 and iOS 15. There are also 2 animated gifs showing the 2 different behaviors in the GitHub project. The relevant code is in ContentView.swift: import SwiftUI struct DismissingView: View { @Binding var isPresented: Bool var body: some View { if #available(iOS 15.0, *) { print(Self._printChanges()) } else { print("DismissingView: body draw") } return VStack { Button("Dismiss") { isPresented.toggle() } Text("Dismissing Sheet").padding() }.background(Color.white) } } struct PausableView: View { var isPaused: Bool // @Binding var isPaused: Bool private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() @State private var counter = 0 var body: some View { Text("Elapsed seconds: \(counter)") .onReceive(timer) { _ in counter += isPaused ? 0 : 1 } } } struct ContentView: View { @State private var presentSheet = false var body: some View { if #available(iOS 15.0, *) { print(Self._printChanges()) } else { print("ContentView: body draw") } return VStack{ Button("Show Sheet") { presentSheet.toggle() } Text("The ContentView's body along with the .sheet() is being redrawn immediately after dismiss, if the @State property `presentSheet` is used anywhere else in the view - e.g. passed to `PausableView(isPaused:presentSheet)`.\n\nBut if the property is passed as a @Binding to `PausableView(isPaused:$presentSheet)`, the ContentView's body is not redrawn.").padding() PausableView(isPaused: presentSheet) // PausableView(isPaused: $presentSheet) } .sheet(isPresented: $presentSheet) { DismissingView(isPresented: $presentSheet) .background(BackgroundClearView()) // to see what's happening under the sheet } } }
2
1
1.7k
Feb ’25
Scene for my "Application's Menu About "My Application""
I am using SwiftUI to create an app and I have figured out how to present a scene for my preferences window. However I have yet to find a way to modify the "About "My App"" scene. I am not even sure how to ask the question on other forums because I keep getting informations on application menus. I would like to find information on accessing/changing other menu entries in the menubar (in SwiftUI) an most specifically I would like to find out how to present a custom window (or at least custom information) when the user selects "About "My App"" I guess I don't need a solution but a pointer to documentation that will help me in my quest.
3
0
1k
Apr ’25
SwiftUI - AsyncImage causing massive tmp folder?
So I have a perplexing situation. I'm loading multiple SwiftUI AsyncImages according to spec (see code below). For some reason, my 1MB app has over 400+ MBs of documents & data. When I view the app's container, I can see that it is caused by a massive number of the images as .tmp files in the "tmp" folder all starting with the name "CFNetworkDownload". It seems that every time an image is loaded, it's stored in here, but does not delete. This makes the app get bigger every time it's opened. What can I do about this issue? Thanks so much! (P.S. I've tried to condense my code down as much as possible for readability, but there's a few files included because I'm not sure where the problem lies.) Main app Swift file: @main struct MyApp: App { let monitor = NWPathMonitor() @State private var isConnected = true var body: some Scene { monitor.pathUpdateHandler = { path in if path.status == .satisfied { if !isConnected { isConnected.toggle() } } else { if isConnected { isConnected.toggle() } } } let queue = DispatchQueue(label: "Monitor") monitor.start(queue: queue) return WindowGroup { isConnected ? AnyView(ContentView()) : AnyView(ContentViewFailed()) } } } The ContentView that's loaded inside the above WindowGroup: struct ContentView: View { var body: some View { TabView { HomeView() .tabItem { Image(systemName: "house.fill") Text("Home") } . . . } } } And finally, the HomeView where the images are being loaded: struct HomeView: View { var body: some View { let urlString = "https://www.example.com/Home.json" if let url = URL(string: urlString) { if let data = try? Data(contentsOf: url) { do { items = try JSONDecoder().decode([Item].self, from: data) } catch { print(error) } } } return NavigationView { List { ScrollView { VStack(alignment: .leading) { ZStack { VStack(alignment: .leading) { Spacer() HStack { AsyncImage(url: URL(string: "https://www.example.com/images/example.png")) { image in image .resizable() .aspectRatio(contentMode: .fill) .shadow(color: Color(red: 0, green: 0, blue: 0, opacity: 0.25), radius: 1) } placeholder: { ProgressView() .progressViewStyle(.circular) } .frame(width: 202, height: 100) } . . . } } } } } } } } I really appreciate your time. Not sure if this could just be a bug with AsyncImage itself.
2
1
1.5k
Sep ’25
fullScreenCover not dismissed if binding changes rapidly.
I'm working on an app targeting iOS 15+ using SwiftUI. The app has several Views that load data from an API in their onAppear() method. While the loading operation is in progress, these views show a loading overlay via .fullScreenCover(). While most of the time this works as expected, I've discovered that if the API operation completes before the overlay's .onAppear() has fired, the overlay gets stuck on screen, i.e. does not dismiss. This bug occurs both in the simulator and on device. This is a simplified version of my implementation: struct MyDataView: View { @EnvironmentObject var store:Store var Content: some View { // ... } @ViewBuilder var body: some View { let showLoadingOverlay = Binding( get: { store.state.loading }, set: { _ in } ) Content .onAppear { store.dispatch(LoadData) } .fullScreenCover(isPresented: showLoadingOverlay) { LoadingOverlay() } } } Log messages tell me that my store is updating correctly, i.e. the booleans all operate as expected. Adding log output to the binding's getter always prints the correct value. Adding a breakpoint to the binding's getter makes the problem disappear. I've found that the chronology of events that lead to this bug is: MyDataView.onAppear() LoadData Binding: true Overlay starts animating in LoadData finishes Binding: false Overlay fires it's onAppear I.e. whenever loading finishes before the fullScreenCover's onAppear is fired, the overlay get's stuck on screen. As long as loading takes at least as long as it takes the overlay to appear, the bug does not occur. It appears to be a race condition between the .fullScreenCover appearing and the binding changing to false. I've found that the bug can be avoided if loading is triggered in the overlay's .onAppear(). However, I would like to avoid this workaround because the overlay is not supposed to carry out data loading tasks.
2
1
1.3k
Feb ’25
Use @AppStorage with Arrays
Hey, I know you can write @AppStorage("username") var username: String = "Anonymous" to access a Value, stored In the User Defaults, and you can also overwrite him by changing the value of username. I was wondering if there is any workaround to use @AppStorage with Arrays. Because I don't find anything, but I have a lot of situations where I would use it. Thanks! Max
2
1
1.3k
Jun ’25
How to add more padding bellow a TextView when the keyboard is shown
When i have TextField inside ScrollView and tap on it the keyboard is shown as expected. But it seems that the TextField is moved up just enough to show the input area but i want to be moved enough so that is visible in its whole. Otherwise it looks cropped. I couldn't find a way to change this behaviour. struct ContentView: View {   @State var text:String = ""   var body: some View {     ScrollView {       VStack(spacing: 10) {         ForEach(1...12, id: \.self) {           Text("\($0)…")             .frame(height:50)         }         TextField("Label..", text: self.$text)           .padding(10)           .background(.white)           .cornerRadius(10)           .overlay(             RoundedRectangle(cornerRadius: 10)               .stroke(.blue, lineWidth: 1)           )       }       .padding()       .background(.red)     }   }     }
4
3
4.0k
Mar ’25
ARQuickLook controls not displaying in SwiftUI
Hi, I'm embedding the QLPreviewController in a UIViewControllerRepresentable. When I view .usdz models I don't see the AR/Object selector at the top, nor the sharing button. I have tried presenting modally with a .sheet modifier and had the same result. What do I need to do to get the controls? Thanks, code attached. Code Spiff
3
0
1.8k
May ’25