Hi, My SwiftUI app is using json to populate a list. I had an array of the names of States that would link to a list of Congressional Representatives from the json file. When I had the json file stored in my app I was able to filter the results in the NavagationLink by using this below. List { ForEach(self.States, id: .self) { States in NavigationLink(destination: HouseList(houseData: self.houseData.filter({ $0.stateFullName == States}))) { Text(States) .fontWeight(.regular) .font(.system(size: 14)) } } }.listStyle(GroupedListStyle()) Now I have moved the json file online so I can update it regularly, but I cannot use the same method to filter my results. I tried to use the State name from the json file, but that creates duplicates base on how many reps that State has. I tried a method to remove the duplicate States, but now the link will only show a single representative. Here is what I am using now. var set: Set = [] let orderedset = fetchHouse.houseData.filter { set.inse
Search results for
SwiftUI List performance
50,605 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi, I have a severe problem with the SwiftUI List view in Xcode 12 (beta). When a List item, which is selected, is removed, the List crashes every time. [General] Row 2 out of row range [0-1] for rowViewAtRow:createIfNeeded: Looks like a bug in SwiftUI to me. What can I do to prevent the crash? I've tried several things already, but with no success. I'm stuck with this problem since 3 days now... Example code: // Example to reproduce bug // * Select no item or other than last item and press button: selection is reset, last item is removed, no crash // * Select last list item and press button Delete last item => Crash // import SwiftUI class MyContent: ObservableObject { @Published var items: [String] = [] @Published var selection: Set = Set() init() { for i in 1...5 { self.items.append(String(i)) } } } struct MyView: View { @ObservedObject var content: MyContent = MyContent() var body: some View { VStack { List(content.items, id: .self
Based on the session video 'Loading and Displaying a Large Data Feed' I observed a performance problem when the number of displayed rows in a List or LazyVStack increases. Instead of an earthquake app lets think of a messaging app. New messages are fetched from a server, injest in a background task into a core data persistent store and displayed with a SwiftUI LazyVStack embedded in a scrollview. The rows in the list have different height. But this is not the problem because I wrote also a test app with a fixed content height for each row. Scrolling through a list of data retrieved by a @FetchRequest works pretty well. I passed the fetched items using a @ObservedObject to the SwiftUI row views so that property faults are only handled for the displayed rows. Row views have also an identifier set so that SwiftUI can reuse them. Everything works fine like in the earthquake example till to the point where the number of fetched items increases (approxi
For some reason this doesn't work for me when I switch to the macOS build. [The documentation][link] lists macOS 11 support on the website (and the docs in Xcode list 10.16), but I'm getting an error that my view has no member 'onOpenURL'. [link]: https://developer.apple.com/documentation/swiftui/anyview/onopenurl(perform:)
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
In my macOS app I have a SwiftUI list that starts like this: List(selection: $selection) { HStack { Label(Staging, systemImage: arrow.up.square) Spacer() WorkspaceStatusBadge(unstagedCount: model.statusCounts.unstaged, stagedCount: model.statusCounts.staged) } (where WorkspaceStatusBadge is a custom view that just contains a Text) I'm trying to set the accessibility ID of that first cell so I can find it in XCUITest. If I apply the accessibilityIdentifier() modifier to the HStack, it instead sets the ID of the two static text elements inside it, and the cell still has no ID. I could find the cell based on the ID of the child staticText, but I have some other cases where this doesn't work as well. If I use .accessibilityElement() on the HStack, then XCUI sees a cell containing a Group element with the ID. This might be workable, but it's certainly not ideal. So how do I set the ID of the cell itself?
In the main screen of the application I need to have the following from top to bottom: A row with a logo and an icon when clicked it shows an alert A row with a text and the edit button for the list EditButton() Search Bar of the list in this case I am just assigning .searchable() for the list The list itself of some cards A button that is just sticked to the bottom of the screen. The problem is in the first two rows. It's worth mentioning that those two rows mentioned above isn't scrolling with the list they are always sticky at the top. I know that this goes against the apple guidelines however, it needs to be done this way. The approaches I did so far was the following (In the following i will refer to the two rows that we are trying to stick to the top as the header as it's a one unit): Trying to stick up the header at the top like I do with the button sticked to the bottom by using .frame(alignment: .top). However, it gets placed under the search bar not above
I have been facing poor scrolling performance when using UIVisualEffectViews in a long List on SwiftUI. Here is my implementation of the UIVisualEffectView: struct BlurView: UIViewRepresentable { var style: UIBlurEffect.Style func makeUIView(context: Context) -> UIVisualEffectView { return UIVisualEffectView(effect: UIBlurEffect(style: style)) } func updateUIView(_ uiView: UIVisualEffectView, context: Context) { uiView.effect = UIBlurEffect(style: style) } } extension View { func blurEffect(style: UIBlurEffect.Style) -> some View { background(BlurView(style: style)) } } And here is the implementation of the List: struct ListView: View { var body: some View { NavigationView { List { Section(footer: Spacer()) { ForEach(People.allCases, id: .rawValue) { person in HStack { Text(person.name) .font(.headline) .multilineTextAlignment(.leading) .padding(13) .frame(minHeight: 50) .background( BlurView(style: .prominent) .mask(RoundedRectangle(cornerRadius: 15, style:
I have a list of items/cells where each item has many elements within it including a button. On tap of a cell, it navigates to screen say ViewA. And on tap of button within the cell, it goes to ViewB. However, on tap of the cell, instead of navigating to ViewA, it randomly navigates to ViewB even though the nav link isActive is disabled. Please suggest! ViewA - List view `List { ForEach(testData, id: .self) { index in ZStack { NavigationLink(, destination:ViewA()).opacity(0) ViewAListItem() }.listRowBackground(Color.clear) .listRowSeparator(.hidden) .background(.clear) } }` In another file, struct ViewAListItem: View { @State var test: Bool = false /// some other code /// /// /// Button(action: { test = true }) { Text(Testing) }.background( NavigationLink(, destination: ViewB(), isActive: $test).opacity(0) ) } Here even though the button is not tapped, variable test is true and navigating to ViewB on tap of cell which should launch ViewAListItem instead. Any issue with this?
I am writing a SwiftUI-based mac app (Big Sur beta 2), which shows a List of items. The list is configured to support selection. I also want to support double tapping on selected items. When I attempt to add a double tap gesture to my list item, it breaks the built-in single tap selection gesture. I have tried using onTapGesture(count: 2) { ... }, .gesture(TapGesture(count: 2)...), and .simultaneousGesture(TapGesture(count: 2)...), with no luck. What is the correct way to add double-tap support to a List without breaking single-tap selection?
SwiftUI List comes with embedded scroll functionalty, which is nice, except...that view has a (white) background at a higher lever than any modifyable view. Result: a background view is layered behind the white background of the scroll view. In the debugger I see that the List encapsulates a Hosting View>View Host>ListCoreScrollView. The latter shows opaque. Thusly, trying to change the background of the List has no effect: the background view will be behind the white scroll view.You can easily try it yourself. Create a list with some random rows.List { ForEach(rows.items)Run the app, then look at the View Debugger: rotate the view and you will see the auto generated while layer in the view hierarchy.My first attempt was setting the background color (to no avail, as described above). I also tried adding a custom ViewModifier. Inside a viewModifier one can set the UITableView.appearance(). However, that is IOS only, it does not work on macOS. Using VisualEffec
I used List(select:) to make it selectable. When scrolling to select many rows, the selected content sometimes disappears. Is running out of memory a problem? While the default app in ios has smooth multi-selection, it is unstable when using swiftui's list function. Multi-select in the mail app, for example, doesn't run out of memory when many rows are selected. How do you achieve this perfection? The code is nothing special. Create a list with List(select:) and rows with ForEach(array, id:.self). I'll attach a video https://i.stack.imgur.com/2px9i.gif
In my app I’ve got a list view and a view for displaying the rows in the list. When I delete an item from that list the app crashes in the row view stating an illegal access. I don’t understand why the row view is rendered again for the deleted item. The list view: import Foundation import SwiftUI struct SpanList: View { @Environment(.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [ NSSortDescriptor(keyPath: Span.startDate, ascending: true) ], predicate: NSPredicate(format: isArchived != YES), animation: .default) private var activeSpans: FetchedResults var body: some View { NavigationView { VStack { List { Section(header: ActiveSectionHeader()) { ForEach(activeSpans, id: .id) { item in NavigationLink(destination: getConfiguredEditView(span: item)) { SpanRow(span: item) } .buttonStyle(PlainButtonStyle()) .listRowBackground(item.color.opacity(0.5)) } .onDelete(perform: deleteItems) } } .listStyle(GroupedListStyle()) }
Hi, I have a list of items on the iPhone that I want to share on the watch. The list would be too big to have the actual file on the watch, so, what's the best way to share the list from the iPhone, and could someone give me a step by step on what to do or point me to a good document? Thanks, Dan Uff
I'm having a lot of performance issues with SwiftUI Lists and I can't seem to find any solution. Currently, if you have a List with 10_000 items and try to filter it, the app hangs for 1 second at the beginning of filtering, looking at Instruments it seems to be an issue with the underlying UITableView to perform the animations. Here's a very tiny example to demo the issue: struct Item: Identifiable, Hashable { let title: String var id: String { title } } @main struct ListFilteringDemoApp: App { private let allItems = (0...10_000).map { _ in Item(title: UUID().uuidString) } @State var searchQuery: String = var filteredItems: [Item] { if searchQuery.isEmpty { // No filter applied return allItems.filter { _ in true } } else { return allItems.filter { item in item.title.localizedCaseInsensitiveContains(searchQuery) } } } var body: some Scene { WindowGroup { NavigationView { List(filteredItems) { item in Text(item.title).id(item) } .navigationTitle(Filtering)
I have a SwiftUI recursive list, created with the (children:) initializer, just like it's shown in the code example here: https://developer.apple.com/documentation/SwiftUI/List#Creating-hierarchical-lists I would like this tree view to be searchable (i.e a user enters a query into a text field and it searches the entire tree at all levels). Displaying a search result which is not at the top level would require its parents to be programmatically expanded. How to programmatically expand certain levels of such a list?