Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

SwiftUI List selection is not consistent across initializers.
When using an initializer like List(selection: $selection) the touch is never recognized as a selection, even if the data objects conform to Identifiable. It doesn't seem to matter much what kind of views each cell consists of. As the title suggests, the touch is correctly recognized as a selection when an initializer like List(identifiableObjects, id: .self, selection: $selection) is used. It is also worth reporting that List(identifiableObjects, id: .id, selection: $selection) does not perform the selection either. This has been checked in Xcode 15 beta 5.
2
0
1.4k
Jul ’23
SwiftUI Outline List Without \.children
Is it possible to get the expandable outline list functionality without using a data model with children? For example, something like this: List { Text(Im a text row) OutlineRow(label: { Text(Outline Title) }, children: { Text(Im a text sub-row) Text(Im another text sub-row) Image(image-row) }) Image(image-row) }
1
0
903
Jul ’20
Reply to List updates very slowly and blocks UI
Still broken in Xcode 11b6. Looks like it'll ship this way, unable to make lists of more than a few tens of items!?Kabe, I don't know what enforce a reload means in SwiftUI. Whether the list is passed by value to the component or is a field of an @ObjectBinding doesn't affect the performance. Either way, the resulting view tree gets diffed, including this horrifically slow implementation on the list.
Topic: App & System Services SubTopic: Core OS Tags:
Aug ’19
Map view in SwiftUI on visionOS: Bad performance with many markers
I am trying to build a visionOS app that uses a map as a central user interface. This works fine on high zoom levels when there are only a couple of markers present. But as soon as I zoom out and the markers number gets to hundreds or even thousands, the performance gets super, super bad. It takes seconds for the map to render, and pans are also laggy. What makes things worse is that the SwiftUI map does not support clustering yet. Has anyone found a solution to this? I found this example by Apple about how to implement clustering: https://developer.apple.com/documentation/mapkit/mkannotationview/decluttering_a_map_with_mapkit_annotation_clustering It works, but it's using UIKit and storyboards and I could not get it transformed into SwiftUI compatible code. I also found this blog post that created a neat SwiftUI integration for a clusterable map: https://www.linkedin.com/pulse/map-clustering-swiftui-dmitry-%D0%B2%D0%B5l%D0%BEv-j3x7f/ However, I wasn't able to adap
2
0
894
Feb ’24
SwiftUI: dynamicTypeSize doesn't work for items in a List
Hi, I have a List and I want to limit the dynamic text size for some of the elements in the list's row item view. I created a test view below. The .dynamicTypeSize(.large) restriction only works if it's applied to the List view, not if it's set for the the ContentItemView in the ForEach below. Is there a reason for this? Do I need to do something else to limit a list row to a certain size? The example only has a text field, but I want to do this for a Image with some text inside it, and I wanted to restrict that text field, but it doesn't seem to work when the view is inside a List row. Please let me know if there's a workaround for it. import SwiftUI import CoreData struct ContentView: View { @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: Item.timestamp, ascending: true)], animation: .default) private var items: FetchedResults @State private var multiSelectedContacts = Set() var body: some View { NavigationStack { List (selection: $mu
2
0
631
May ’24
Reply to Cannot get drop action to trigger (Xcode 26 beta 3)
Since the drag source and the drop destination are the same, I wonder if you have tried to use onMove modifier: https://developer.apple.com/documentation/swiftui/dynamicviewcontent/onmove(perform:) List(items) { ForEach(items) { item in HStack { Text(item.value) Spacer() } } .onMove(perform: moveItems) /// ... func moveItems(from source: IndexSet, to destination: Int) { items.move(fromOffsets: source, toOffset: destination) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jul ’25
recycling of list cells swiftui on scroll data
In my SwiftUI app, I have a data from an array. While scrolling through the list, the cells are being recycled, which is great. However, I'm puzzled because it seems that the data isn't being refetched as I scroll, which is contrary to what I expected. I want to understand why the data isn't being refetched for recycled cells and if this is expected behavior. class HistoryViewModel: ObservableObject { @Published var filteredContacts: [HistoryData] = [] func updateFilteredContacts() { filteredContacts = HistoryCallDataService().savedEntities if self.searchText.isEmpty { self.filteredContacts = filteredContacts } else { self.filteredContacts = filteredContacts.filter { contact in contact.firstName?.localizedCaseInsensitiveContains(self.searchText) ?? false || contact.lastName?.localizedCaseInsensitiveContains(self.searchText) ?? false || contact.telephone?.localizedCaseInsensitiveContains(self.searchText) ?? false } } } The List: List{ ForEach(vm.filteredContacts.reversed())
0
0
1k
Aug ’23
SwiftUI macOS performance issue when frequently updating content in the UI
Hi, I'm building a SwiftUI MacOS app that requires text in a section of the UI to be frequently updated, as the content changes every 0.2-0.5 seconds. The attached sample code represents portion of my UI with elements positioned as they will be, but it's quite CPU intensive and is marked as High Energy Impact, consuming about 13%, and I don't know how to make it better. An acceptable range would be up to 3% and a rating of Low Energy Impact. I tried adding .id(identifier) to portions of the UI in order to prevent redraw but it did not help. I also tried adding .drawingGroup() to portions of the UI in order to render them in Metal but it also did not improve performance. Lastly, I modified the ForEach() wrapper to use a List and it reduced the CPU utilization by half, but it's not something I want to use as I don't like having both vertical and horizontal scrollbars without being able to remove them. Thanks in advance for your help. I'm running Xcode 12 Beta 6 on macOS Catalina 10.15
0
0
839
Aug ’20
Adding an ondelete for a CoreData list in SWIFTUI
Hi What do I define in the OnDelete to set what to delete. code: Environment(.managedObjectContext) var moc @FetchRequest(entity: Faces.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: Faces.facename, ascending: true), NSSortDescriptor(keyPath: Faces.relationship, ascending: true), NSSortDescriptor(keyPath: Faces.birthday, ascending: true), ] ) var DBFaces: FetchedResults var body: some View { NavigationView { List { ForEach(DBFaces, id: .self) { face in Text((face.facename ?? “-“)”) .font(.title) .foregroundColor(.secondary) } } // foreach .ondelete ( ???? ) .padding() }//List } // NavView } // View
0
0
400
Sep ’20
Performance in Large Datasets (SwiftUI+SwiftData app)
Hi everyone, In the simple app below, I have a QueryView that has LazyVStack containing 100k TextField's that edit the item's content. The items are fetched with a @Query. On launch, the app will generate 100k items. Once created, when I press any of the TextField's , a severe hang happens, and every time I type a single character, it will cause another hang over and over again. I looked at it in Instruments and it shows that the main thread is busy during the duration of the hang (2.31 seconds) updating QueryView. From the cause and effect graph, the update is caused by @Observable QueryController .(Bool). Why does it take too long to recalculate the view, given that it's in a LazyVStack? (In other words, why is the hang duration directly proportional to the number of items?) How to fix the performance of this app? I thought adding LazyVStack was all I need to handle the large dataset, but maybe I need to add a custom pagination with .fetchLimit on top of that? (I understand that ModelActor would be
1
0
191
Jan ’26
SwiftUI List with Selection is Highlighting even in non-edit mode
I recently updated my xcode and compiled my application developed in SwiftUI. The SwiftUI List started to behave different. List has Selection parameter for EditMode selection. However, now the list items are being selected and highlighted with grey highlighted color, even in a non-edit default mode. Ideally, it should only select the list item in edit mode. It is how it worked before. But now when the list item is tapped in non-edit mode, it is getting selected. Please, let me know how to make list with selection to highlight only in editmode. import SwiftUI struct ContentView: View { struct Ocean: Identifiable, Hashable { let name: String let id = UUID() } private var oceans = [ Ocean(name: Pacific), Ocean(name: Atlantic) ] @State private var multiSelection = Set() var body: some View { NavigationView { VStack { List(oceans, selection: $multiSelection) { ocean in Text(ocean.name) } .toolbar { EditButton() } } .padding(
5
0
4.8k
Sep ’22
SwiftUI NavigationLink in List on iOS 14
Hi everyone, I'm experiencing some unwanted behaviour in my app on iOS 14. When tapping on a NavigationLink in a List, the Cell keeps being highlighted even when navigating back from the detail view. Only if I selected another Cell, the highlighting disappears. But therefore the other Cell is now highlighted. Is there any way to remove this behaviour? Running on iOS 13, everything was normal. The only workaround is to attach .id(UUID()) to the NavigationLink. But this will cause a flickering of all Cells when navigating back from the detail view and losing the scrolling position of the list. Thanks for any help or hints.
12
0
12k
Sep ’20
SwiftUI List on macOS prematurely loads every row
I'm observing a weird issue with SwiftUI Lists on macOS (they do work as expected on iOS). The problem is that the List calls the init & body of every row, even if those rows are not on screen (and might never be shown). If I replace the List with a ScrollView + LazyVStack, it does work as expected (only those rows which are going to be rendered get their init & body called). Of course, this is is not an ideal workaround because you loose the built-in benefits of using a List (mainly selection in my case). I did expect that under the hood, SwiftUI would use the same mechanism as NSTableView (which loads cells on demand). Historically I'm an iOS dev, so I'm used to cellForRowAtIndexPath coming from UITableView. Here's a quick gist demonstrating the issue: import SwiftUI @main struct SwiftUIListVSLazyVStackApp: App { let numbers = (0...100).map { $0 } var body: some Scene { WindowGroup { /* List calls the init & the body of *eve
0
0
964
Apr ’22