SwiftUI performance is much slower on macOS than on iOS. macOS running SwiftUI is even slower than the iOS simulator. As a simple example, create a List with a few hundred rows (anything over 100 gets pretty bad). macOS scrolling gets unacceptably slow. This is made even worse if the rows have interactive items like Slider or TextField (think a medium complexity inspector). Take the same exact code and Build and Run on iOS and it feels much smoother. Is this an issue with the Window Server? I keep hearing from Apple that SwiftUI is the future of UI for Apple Platforms. And I believe you. But we’ve been waiting a year for performance improvements so that we can seriously consider SwiftUI in our new products and they haven’t come to macOS. Can we expect to see a fix? If SwiftUI isn’t the right framework for multi-platform pro applications (image rendering/editing) then what is? Note that using Equatable helps stop the entire view from recom
SwiftUI List performance
44,603 results found
Post
Replies
Boosts
Views
Activity
Hi, When using SwiftUI ‘List’ with a large number of elements (4000+), I noticed a significant performance issue if extracting the views inside the ‘ForEach’ block into their own subview class. It affects scrolling performance, and using the scroll handle in the scrollbar causes stutters and beachballs. This seems to happen on macOS only ... the same project works fine on iOS. Here's an example of what I mean: List (selection: $multiSelectedContacts) { ForEach(items) { item in // 1. this subview is the problem ... replace it with the contents of the subview, and it works fine PlainContentItemView(item: item) // 2. Uncomment this part for it to work fine (and comment out PlainContentItemView above) /*HStack { if let timestamp = item.timestamp, let itemNumber = item.itemNumber { Text((itemNumber) - (timestamp, formatter: itemFormatter)) } }*/ } } struct PlainContentItemView: View { let item: Item var body: some View { HStack { if let timestamp = item.timestamp, let i
This is a question I've been dealing with and don't know whether or not it is intended or being worked on atm. Basically I've found that when you append items to a List that triggers the List to immediately re-evaluate all pre-existing items in the List (unnecessarily). While re-evaluation as I'm told is not really that expensive if the List has 1000 items there is still a decent amount of overhead that this cause. Am I using List the wrong way or is Apple working on optimizing aspects of SwiftUI like this?
I'm struggling with getting a hierarchical SwiftUI List to perform well with large data sets. Here's a demo repo: https://github.com/lemonmojo/swiftui-hierarchical-list-performance There are three main problems: Rendering of the list is slow if there are many items. (Just start the app and wait for the list to be rendered.) Changing the selected item is very slow. (Tap/Click an item and wait for the selection to change.) Updating the list is slow. (Press the Shuffle button.) On an iPhone 13 Pro, it takes 6 seconds from tapping the app icon to the list being rendered. This was timed with a release build. Once the list has been rendered, it takes 8 seconds for the selection to change when tapping an item. Tapping the Shuffle button results in a 2 seconds delay before the updated list is rendered. All three problems are much more pronounced on macOS (tested on a Mac Studio M2) where it even takes minutes(!
I'm having issues with the scrolling performance in my app. I use CloudKit to store a list of Items. I access these Items with @FetchRequest var items : FetchedResults I created a List with a ForEach inside to iterate over the items and pass them to a ChecklistItemView. The ChecklistItemView accesses the Item as an @ObservedObject. This all works fine and I am able to edit the items with the Textfields but the performance when scrolling is very bad. On my iPhone 12 mini I get light stuttering and on my older iPad pro it gets very bad. Interestingly everything is smooth when the item is just displayed with Text(). My guess is that the Textfields update the item during binding when the TextField appears on screen. This is updating the whole list of items then triggering a redraw of all Textfields, resulting in a stuttering scrolling experience, because the view is redrawn again and again. It does not get worse with longer list. It is enough to fill the scree
I got a problem here. I made two List and both Lists have 'onMove()' function. I expected that if I start to drag a component in the List, it can only be droppable in the List which I started drag. However, the component can be dragged to another List and when the component dropped, it shows an error. It is the only bug in the project with macOS target SwiftUI project. Not in ios target. Is there anybody who has an answer?
I have quite a bit of material about SwiftUI Lists. However, I seem to be lacking information about how to respond to an item being selected. I put selected into quotes because my idea of selecting an item is different from putting a list into selection mode. For example, in the book SwiftUI for Masterminds discusses in Chapter 10 about presenting a selection tool when a List is initialized with the selection attribute. The selection tool presents checkboxes (circles actually) that allow the user to select one or more items in the list. This type of selection is not what I am thinking about. When I refer to selecting an item I mean tapping or clicking (on a Mac) an item. This action fires an event that the application responds to. This is not necessarily a navigation event. It might be that the appropriate response is send a message to a remote site or to perform a calculation using the item that was tapped or clicked. Thus, the complexity of navi
I have a SwiftUI List with multiple Sections. Now I want to to move and delete whole Sections without but not the items within the section. Currently I am doing the following: swift List { ForEach(items) { item in Section(header: Text(item.name)) { Group { NavigationLink(Item List, destination: ContentListView(item: item)) } .deleteDisabled(true) .moveDisabled(true) } } .onMove(perform: { indexSet, destination in items.move(fromOffsets: indexSet, toOffset: destination) }) .onDelete(perform: { indexSet in items.remove(atOffsets: indexSet) }) } .listStyle(SidebarListStyle()) but with this I can not change anything. Is this even possible with standard SwiftUI?
Hello, I am having an issue at the moment. I noticed for iOS 15 when you have made a list using SwiftUI, VoiceOver would describe which cell is being moved to adjacent to it. Now with iOS 16 it VoiceOver doesn't say anything while being moved up or down. Here is a sample code of what I am speaking of. struct SampleView: View { let alphabetArray = [a, b, c, d, e, f] var body: some View { List { ForEach(alphabetArray, id: .self) { letter in Text(verbatim: letter) } .onMove(perform: move) } .environment(.editMode, .constant(.active)) } private func move(from source: IndexSet, to destination: Int) { } }
I have a performance issue with List when I have a large amount of data that is replaced. Given the code below, a data set of about 3500 name items are loaded from a fetch request. Depending of the selected gender in the segmented picker these items are filtered and the displayed in the List. When the List first render I have no performance issue with the loading and rendering of items. It scrolls nicely and smoothly through 1700 items. But as soon as I switch gender through the segemented picker it takes about 30-45 seconds to render the List again.I think this has to do with removing 1700 items and the inserting 1500 items again from the List. Is there a best practice how to reload a large amount of items in SwiftUI? Or can I reset the List before I load it again, since there is no issue initially.Anyone else having issue same issue?struct NameList: View { @ObservedObject fileprivate var global = GlobalSettings() @FetchRequest(
I am trying to recreate the stock Reminders app in SwiftUI. However, looking at the top 2x2 grid and then the account-based sectioned list of reminder lists, it seems nearly impossible to replicate as the sectioned list must essentially be a subview of a scrollView with the grid as another subview above it as the grid scrolls alongside the list of lists. Having the grid as an element in the list works, but has the row separators. Having a scrollView that has the Grid and then a List as children makes the list have a height of 0. Any thoughts?
Hi I am developing an app with swiftUI. Here is the code of a map view. I create customized annotations and show them on the map view. The issue is that when I drag or zoom in/ out on the map view. The app is so slow. The fps decrease to about 20 - 30 from 60. I use instruments to analyze this app. The result shows that there are thousands of times annotation render. I think that the reason for this issue may be off-screen rendering. But I don't know how to solve it. Looking forward to your help. swift Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true, userTrackingMode: $trackingMode, annotationItems: result, annotationContent: { mark in MapAnnotation(coordinate: CLLocationCoordinate2D(latitude: mark.lat, longitude: mark.long)) { Button {withAnimation { self.selectedGymUid = Int(mark.uid) }} label: {RoundedGymIconOnMapView(name:mark.name) .clipShape(Circle()) .overlay(Circle().stroke(selectedGymUid == Int(mark.uid) ? Color(.green).opacity(0.5) : AppColor.shared.joggingCol
I am developing an application that allows users to create recipes. The recipes can only contain ingredients from a pre-selected list. I'm looking for something where, when I select a text field, a list pops up and, when I select an item in that list, it will dismiss the list view and populate the text field with the item that was selected. Does something like this exist natively in SwiftUI or in some 3rd party library?
Hi folks, I am new to SwiftUI. I've got the following small code. All I want is to refresh the List after pull-to-refresh. Is there any reloadData ? Thanks in advance! import SwiftUI import SwiftUIRefresh struct ContentViewFavorite: View { let posts = Data.posts() @State private var isShowing = false var body: some View { List { ForEach(posts) { post in PostViewFavorite(post: post) }.padding(.all, 20) }.pullToRefresh(isShowing: $isShowing) { self.isShowing = false } } } struct ContentViewFavorite_Previews: PreviewProvider { static var previews: some View { ContentViewFavorite() } }
Hi there, I'm learning SwiftUI now it seems interesting (it was before, but more this year ^^). I try to understand why as soon as I add navigationBarItems into my NavigationView, SwiftUI transform my list into a grouped cell. Also, I follow the code shown in Introduction to SwiftUI session this Tuesday and it seems that toolbar is really a toolbar instead of putting everything on navigation bar like it shown. Is anyone get the same result ?