Search results for

swiftui

16,623 results found

Post

Replies

Boosts

Views

Activity

Reply to Combine not working in background tasks on watchOS 26
Well I tried both styles. The initial code was the swiftui .backgroundTask modifier which worked in iOS 18. I created a core data based logger to see where the hiccup was. I noticed data was indeed being read by the anchored queries from HealthKit. That data was then sent to a couple of published properties in observable objects which served as the start of the combine pipelines. In ios18 that led to updates that were critical for updating widgets. In iOS 26, the combine pipelines were not activated. So I switched back to the previous method of background tasks, ie wkapplication.scheduleBackgroundRefresh(...) That also did not allow any combine pipelines to happen. In the end, I had to rip out combine from the watch and use didSet and custom handler blocks. While that did work, obviously it's not as full featured (ie, you can't debounce). After using blocks, things went back to functioning properly. Thoughts?
Oct ’25
Reply to Picker using SwiftData
I am missing something because I can get the picker to appear with the proper selections but the picker does not register my choice (no check mark appears and the text in the picker window is blank after I move to the next field. Picker(Select a type of contract, selection: $contractType) { ForEach(typeOfContracts, id: .self) { typeOfContracts in Text(typeOfContracts.typeCode) .tag(contractType) } } Did you mean to use the above picker to allow a user to select multiple contract types (given that contractType is an Array)? If yes, that won't work because SwiftUI picker doesn't support multiple selections. You will need to implement the feature with other UI elements, such as Menu + Toggle or your own view. Best, —— Ziqiao Chen  Worldwide Developer Relations.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
List jumps back to the top
Following on from this thread: https://developer.apple.com/forums/thread/805037 my list of items is now correctly maintaining state (no more disappearing rows), but I'm now hitting a really annoying issue: Every time something changes - even just changing the dark mode of the device - the entire list of items is refreshed, and the list jumps back to the top. A simple representation: // modelData.filteredItems is either all items or some items, depending on whether the user is searching List { ForEach(modelData.filteredItems) { item in ItemRow(item: item) } } When the user isn't searching, filteredItems has everything in it. When they turn on search, I filter and sort the data in place: // Called when the user turns on search, or when the searchString or searchType changes func sortAndFilterItemsInModelData() { modelData.filteredItems.removeAll() // Remove all items from the filtered array modelData.filteredItems.append(contentsOf: modelData.allItems) // Add all items back in let searchString: String = modelDa
9
0
233
Oct ’25
Reply to List jumps back to the top
Yes, I change the UI when colorScheme changes, otherwise what's the point of that environment variable? For example: RoundedRectangle(cornerRadius: 8) .shadow(color: (colorScheme == .dark ? Color.systemGray.opacity(0.6) : Color.systemGray3.opacity(0.9)), radius: 4, x: 0, y: 0) Is there some other way of doing this? If I create a new colour in Assets with a dark and light appearance to cover that use case, I would have to create tons of colours to cover every other use case, i.e.: .background(colorScheme == .dark ? Color.green : Color.white) .background(colorScheme == .dark ? Color.blue : Color.red) What is the reason that SwiftUI will redraw a view - and bounce you back to the top of a List of views - because Dark Mode was turned on? This is how modelData is created: // A global: let dataService: DataService = DataService.shared // The singleton: final class DataService { static let shared = DataService() private init() {} let coreData: CoreData = CoreData() let modelData: ModelData = ModelData() } T
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to List jumps back to the top
Seems like you have some UI which needs to change its appearance based on color scheme so SwiftUI reads the color scheme value from the environment and your view updates. Because of the way State works, transient instances of ModelData could be created and destroyed. Are you performing any side effect-like work in the model initializer? You should defer side effect-like work in the initializer to task or onAppear modifier.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
How to display a toast view above both main content and FullScreenCover in SwiftUI?
I'm using a ZStack with viewA() and a toast viewB(). I present a FullScreenView() using .fullScreenCover(isPresented:). ZStack { viewA() viewB() // toast view } .fullScreenCover(isPresented: $isPresented) { FullScreenView() } I want viewB (the toast) to appear above both viewA and the FullScreenView. I only found this approach works but it has duplicate code. ZStack { viewA() viewB() // toast view } .fullScreenCover(isPresented: $isPresented) { ZStack { FullScreenModalView() viewB() // toast view } } What are all possible approaches to achieve this in SwiftUI? Any advice or code samples would be appreciated!
Topic: UI Frameworks SubTopic: SwiftUI
1
0
98
Oct ’25
Menu List Error
Hi, I'm trying to have a menu at the trailing edge of a list but when I do so I am getting UIKit errors. I pasted my sample code below. Not exactly sure how to fix this. ForEach(0..<100) { i in HStack { Text((i)) Spacer() Menu { Text(Test) } label: { Image(systemName: ellipsis) } } } } Adding '_UIReparentingView' as a subview of UIHostingController.view is not supported and may result in a broken view hierarchy. Add your view above UIHostingController.view in a common superview or insert it into your SwiftUI content in a UIViewRepresentable instead.
Topic: UI Frameworks SubTopic: SwiftUI
2
0
164
Oct ’25
Reply to Menu List Error
That seems like it could be a bug in SwiftUI. Please file an bug report using Feedback Assistant and inlcude a sample project that reproducses the issue. Once you file the request, please post the FB number here. If you're not familiar with how to file bug report, take a look at Bug Reporting: How and Why?
Topic: UI Frameworks SubTopic: SwiftUI
Oct ’25
Reply to List jumps back to the top
I still can't figure out a way to stop the list from jumping back to the top when the device's Dark Mode setting changes. Why does SwiftUI think the data is different? A user changing the system appearance in isolation should not cause the the list scroll position to change. However. the body of a view will be called whenever you change the view such as by passing a value into its initializer from the parent view, and that value changes, or a dynamic property changes either explicitly because you changed an @State variable, or implicitly because you read something from the environment and that value changed such as like the color scheme. You can include let _ = Self._printChanges() in a view body while debugging to see why the view’s body was triggered.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to Menu List Error
I ended up being able to get rid of the error. By creating the menu in UIKit and wrapping it to SwiftUI, the warning and visual error went away. Still not an ideal fix though.
Topic: UI Frameworks SubTopic: SwiftUI
Oct ’25
Reply to How to have clickable/tappable buttons where the toolbar is supposed to be?
Hello Ikester, have you tried giving the button a modifier .zIndex() or applying an .overlay() to the detail view of your NavigationSplitView? Maybe if you implement the two buttons in an .overlay() and give those buttons an .offset() as well it might work. NavigationSplitView() { //your navigation views } detail: { //your content views } .overlay() { Button(click me) {} .offset(CGSize(width: 10, height: 10)) } For accurate positioning you could add a GeometryReader(){geometry in}. If this doesn’t work this maybe will: .toolbarVisibility( .hidden, for: .navigationBar, .tabBar) you add this modifier to your first nested view inside the NavigationSplitView. This is much better explained here: https://developer.apple.com/documentation/swiftui/view/toolbarvisibility(_:for:) I hope this helps.🙂
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to List jumps back to the top
I'm not sure either, @Claude31, but before I implemented the @StateObject for my model data this didn't happen. I understand that using @StateObject is the correct thing to do, but why does SwiftUI throw in these extra problems when you're doing things the right way?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25
Reply to List jumps back to the top
Why does SwiftUI think the data is different? Maybe it's not that it evaluates data has changed but just that it needs redraw (even only for dark mode switch). But I'm not expert enough in SwiftUI to be sure. That's an issue I find with SwiftUI, understanding and possibly controlling what it is doing in the back or find a workaround. I'm still much more comfortable with UIKit.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’25