Hi there, I am still quite new to Swift. Is there a easy way to search a list with navigation links to other swift pages? Thank you so much for your help! Laurin
Search results for
SwiftUI List performance
50,598 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Has anyone else noticed that macOS Sequoia 15.5 has a regression in SwiftUI Table scrolling performance? I have complex Tables in a SwiftUI app and they scroll adequately on macOS 15.4.1 but hang, beachball, and stutter while scrolling on macOS 15.5. The exact same build is running in both cases. (I've even reduced the table to three simple columns of text and STILL fail to get entirely smooth scrolling on macOS 15.5.) It's like someone just fundamentally broke Table on macOS. Has anyone else encountered this?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Hello, I am unable to move multiple rows in a list, it only allows for one at a time. However, I am able to select multiple rows. Here is my code: import SwiftUI struct ContentView: View { @State var items = [Test 1, Test 2, Test 3, Test 4, Test 5, Test 6] @State var selectedItems: Set = .init() var body: some View { NavigationView { List(selection: $selectedItems) { ForEach(items, id: .self) { item in Text(item).tag(item) } .onMove(perform: { indices, newOffset in withAnimation { self.items.move(fromOffsets: indices, toOffset: newOffset) } }) } #if os(iOS) .navigationBarItems(trailing: EditButton()) #endif } .padding() } } I need all the selected rows to move when dragged. Any help would be greatly appreciated, I have tried, and can not find any way to do it. Thanks, Dev_101
I am building a list in SwiftUI. In my view, I want the 'Jesse Lingard' and 'Manchester United' text to be next to the image but they are appearing underneath. How do I fix this?
You should checkout EditMode environment value. It isn't a 1-1 functionality mapping, but certain built-in SwiftUI views will automatically alter their appearance and behavior in edit mode. For example, a List with a ForEach that’s configured with the onDelete(perform:) or onMove(perform:) modifier will provide controls to delete or move list items while in edit mode.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Does anyone have some resources to recommend for learning more about measuring and optimizing SwiftUI performance and rendering? I haven't seen a ton from Apple that looks like it's going to help me more. I did find two sessions from WWDC 2023. The Demystify SwiftUI performance session[1] does tell us the _printChanges function can help tell us when component bodies are computed. I see how I can attach this to a component that I built… I'm not (yet) sure if I have the ability to run this on arbitrary system components in my component graph. The Analyze hangs with Instruments session[2] does walk us through using the SwiftUI Instruments to measure body computations. Does anyone have any more resources along these lines for learning more? SwiftUI is closed source… so we don't really have easy visibility inside to see for ourselves. Bummer. Are there any additional debug APIs (like _printChanges) that can help for local development? I'm also interested to lea
I am working with a ScrollView and a LazyVStack that can have many rows, sometimes 500 or more. My rows are expandable on tap. Performance of expand/collapse is unacceptable when the number of rows exceeds 100. The more rows, the more performance degrades. This is the gist of my code: struct PlaceView: View { tt/* ... */ ttvar place: Place tt@Binding expandedPlaceId: Int ttvar content: some View { ttttVStack(alignment: .leading) { ttttttText(place.name) tttttt ttttttif self.expandedPlaceId.wrappedValue == place.id { ttttttttVStack(alignment: .leading) { ttttttttttText(place.city) tttttttt} tttttt} tttt} tt} } struct PlacesListView: View { tt/*...*/ tt@State expandedPlaceId = -1 ttvar body: some View { tttScrollView { ttttLazyVStack { tttttForEach(places, id: .id) { place in ttttttPlaceView(place: place, expandedPlaceId: self.$expandedPlaceId) tttttttt.onTapGesture { self.selectDeselect(place) } tttttttt.animation(.linear(duration: 0.3)) ttttt} ttt } tt } t} } I created an init function in Pl
I have a non trivial application that currently uses a UITableView to display numerous different types of cells. I'm working on a refactor, and have been attempting to use SwiftUI with List. My concern is that this may not be fully ready for the types of things I want to do in a high volume application. There are some basic things still missing from List that were in UITableView, like pull to refresh and custom swipe actions. I can write custom implementations, but I've started thinking more about the future of UIKit for lists vs SwiftUI. Apple is continuing to improve upon UICollectionView in particular, and it has a lot more customizability. I'm wondering - for non trivial lists, is UIKit with SwiftUI cells the preferred way to go? Where exactly does SwiftUI List fit? Is it still a work in progress that will eventually have parity with UIKit counterparts? Thanks!
I have a use case where I want to navigate to a destination view but also perform an event when the user interacts. Outside of a List this code seems to work: NavigationLink(destination: MyDestinationView()) { HStack { /* content here */ } } .simultaneousGesture(TapGesture().onEnded { /* my action */ }) However, once you put that in a List either the navigation or the action, not both, will fire. Typically tapping anywhere in the HStack will navigate, but tapping on the Text objects will fire the action and not navigate. Is this an issue with List or is there an intended way of doing this that I am not seeing? I also messed with contentShape and it ended up making the HStack fire the action and only the very edges of the cell would navigate. Like the rowItem could only handle 1 gesture event at a time. I tried something like in the ForEach creating a view that had a body of: (view also had a state var of shouldNavigate) Group { NavigationLink(destination: MyView(), isActive
In the following code, click/touch anywhere on any row of the list deletes that row. This is not expected. Only the click/touch on the xmark button should delete that row. import SwiftUI struct MainView: View { private let arr: [String] = [one, two, three] var body: some View { List(arr, id: .self) {item in SecView(name: item) } } } struct SecView: View { var name: String @State private var show = true var body: some View { if show { HStack { Text(name) Button(action: { show = false }, label: { Image(systemName: xmark) }) .border(.yellow) } } } } @main struct XApp: App { var body: some Scene { WindowGroup { MainView() } } } Please check. I ran the above code for iPAD air (5th generation).
This has been broken for over 5 years now. I see 2 different behaviors in 2 different SwiftUI apps. This makes SwiftUI not ready for prime time apps, but I just have tools right now. The VStack { List } doesn't scroll to the item in a long list. The selection moves to the next item in the list, but can't see it. This is just basic UI functionality of a list. UIListView doesn't have this issue. The NavigationView { List { NavigationLink }} wraps around back to the top of the list when pressing down arrow past the last visible item, but there are plenty more list items to visit.
I'm working with a SwiftUI view that contains a Map with numerous Annotations (ranging from 30 to 100). Alongside these, there's a specific annotation that changes based on the user's selection from a list. The list selection might change rapidly, possibly up to 10 times a second. When the selected annotation is updated, it seems that all the annotations on the map view get reloaded. This results in high CPU usage and a significant drop in screen refresh rate, especially during rapid selection changes. How can I optimize this to only reload the selected annotation in the map view instead of all annotations when the selectedAnnotation is changed? Here's the relevant pseudo code: @State var annotations: [MKAnnotation]() @State var selectedAnnotation: MKAnnotation? Map { ForEach(annotations.indices, id: .self) { idx in let anno = annotations[idx] Annotation(, coordinate: anno.coordinate) { Circle() .stroke(.black, lineWidth: 4) .fill(.white) .frame(width: 8, height: 8) } } if let selec
Is there a way to have a list in SwiftUI that has a max width in grouped style like the Settings app on an iPad Pro 12.9 ? I have tried with something like: List { t Text(Hello, world!).padding() } .frame(maxWidth: 600) .listStyle(InsetGroupedListStyle()) and it gets me half the way. The list is centered with the max width. However, I can't set the background in a way that it covers the whole page. The List view sets its background to the system grouped background as expected for InsetGroupedListStyle. And I can wrap the list in a HStack and set a background on that. But the list even add background color up in the navigation bar, but that I cannot change. So I still can't figure out a way to do it. HStack { tSpacer() tList { ttText(Hello, world!).padding() t} .frame(maxWidth: 600) .listStyle(InsetGroupedListStyle()) Spacer() } .background(Color(UIColor.systemGroupedBackground)) I can probably accomplish what I want with just a ScrollView and make
I'm new to swiftUI.There must be a way to make this better.For example if I add an Item (for example: name5) to names I have to add a new HStack Block in my Code.How can I do this more efficient?import SwiftUI struct name: View { let names = [name1, name2, name3, name4] var body: some View { List { VStack { HStack { Image(names[0]) Text(names[0]) } HStack { Image(names[1]) Text(names[1]) } HStack { Image(names[2]) Text(names[2]) } HStack { Image(names[3]) Text(names[3]) } } } } } struct monsterList_Previews: PreviewProvider { static var previews: some View { name() } }Maybe something like this.Pseudocode: foreach i in names.count: HStack { Image(names[i]) Text(names[i]) }if I add an Item to names it should automatically increase the list by the new element.thanks in advance
I have isolated this very simple piece of code. Basically I get a data representation of an image from Core Data and display it in SwiftUI using Image. The problem is, it's trying to load the image again every time you scroll the scroll view, which leads to a performance issue. The part that I do not understand is, that this only happens while the Image is wrapped in a GeometryReader and only when reader.frame is accessed somewhere like in the Text object. If I comment out that Text object, everything is smooth and the image is only loaded once. Is this a bug or am I misunderstanding something here?var backgroundImage: UIImage { print(LOAD IMAGE) if let imageData = gameLocal.backgroundImage { return UIImage(data: imageData)! } else { return Constants.placeholderImage } } var body: some View { ScrollView { GeometryReader { reader in Image(uiImage: self.backgroundImage) .resizable() .foregroundColor(Color.gray) // Text(Offset.y: (reader.frame(in: .global).minY)) } .frame(minWidth: 0, maxWidth: