Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

SwiftUI not rendering the background view for List when selected in edit mode
I have a view where the user can configure which train lines are shown on a map. I'm having an issue where the list row background is ignored for all of the cells which are selected. Here is code that I am using: struct MapConfigurator: View { @Binding var routes: Set<Route> var body: some View { List(selection: $routes) { Section(header: Text(Show)) { ForEach(Route.allCases, id: .self) { route in Text(route.name) .foregroundColor(route.textColor) .listRowBackground(route.color) .tag(route) } } } .navigationBarTitle(Configure Map) .listStyle(GroupedListStyle()) .environment(.editMode, .constant(.active)) } } struct MapConfigurator_Previews: PreviewProvider { static var previews: some View { NavigationView { MapConfigurator(routes: .constant([.red, .green, .blue])) } } }
1
0
1k
Aug ’20
Not sure how to add Prev/Next buttons in my SwiftUI List's Detail view.
I have a SwiftUI app with a List displaying an array of model objects. When the user taps a list item we see its detail view. I want to add previous and next buttons to my detail view, but I'm not sure what needs to happen when previous/next are tapped. (see code below for what I'm looking to do) My first thought is to make the model variable in the DetailView be a binding, but I'm not sure how this would tie in with the NavigationLink 'stuff' any/all suggestions appreciated. thanks! class Model: Identifiable { var modelValue: Int init(modelValue: Int) { self.modelValue = modelValue } static let testData = [Model(modelValue: 3), Model(modelValue: 7), Model(modelValue: 31)] } class ModelManager { static let shared = ModelManager() let modelList = Model.testData func previous(for model: Model) - Model? { if let index = modelList.firstIndex(where: {$0.modelValue == model.modelValue}) { if index 0 { return modelList[index - 1] } } return nil } func next(for model: Model) - Model? { if l
1
0
1.6k
Mar ’21
SwiftUI reuses List View when it should draw a completely different one (possible bug?)
I created a List for a settings menu with two sections where you can reorder/add/remove a set of pages. It should work similar to Apple's Today Widget editing menu where you can add and reorder items.Connector class code snippet:class SettingsConnector: ObservableObject { enum DetailsPage { case page1 case page2 case page3 func printed() -> String { switch self { case .page1: return Page 1 case .page2: return Page 2 case .page3: return Page 3 } } } @Published var detailsPages: [DetailsPage] = [.page1, .page2] @Published var hiddenDetailsPages: [DetailsPage] = [.page3] }SwiftUI code snippet:List { Section { ForEach(self.connector.detailsPages, id: .self) { page in HStack(spacing: 0) { Text((page.printed())) Spacer() } } .onMove { (source, destination) in self.connector.detailsPages.move(fromOffsets: source, toOffset: destination) } .onDelete { (rows) in rows.forEach { (i) in let page: SettingsConnector.DetailsPage = self.connector.detailsPages[i] self.connector.detailsPages.remove(at: i) s
5
0
2.5k
Apr ’20
Reply to SwiftUI tableview warning
This is benign. It's appearing because SwiftUI is using a table view in the background to perform layout calculations without actually putting it on-screen. In the SwiftUI use case, this is to be expected, and doesn't seem to have any particular negative effects.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’19
SwiftUI self-sizing list cell on Mac don't seem to work
I have the following code written using SwiftUI 2.0, Xcode 12.0 beta 5 on OS 11 beta 5. struct ContentView: View { var body: some View { GeometryReader { geometry in List { ForEach(data, id: .id) { article in ArticleCell(article: article) } .frame(width: geometry.size.width) .listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0)) } .listStyle(PlainListStyle()) } } } struct Article: Identifiable { let id: String let title: String let description: String } let data = [ Article( id: UUID().uuidString, title: Title 1, description: NASA has awarded the Strategic Research and Analysis, Communications, and Exhibits Services (SRACES) contract to Media Fusion LLC of Huntsville, Alabama, to provide comprehensive strategic research and analysis, communications, and exhibits services at the agency’s Marshall Space Flight Center in Huntsville, Alabama. ), Article( id: UUID().uuidString, title: Title 2, description: Girl Scouts from across the nation will pose questions next week to NASA astrona
0
0
1.4k
Aug ’20
SWIFTUI List object .onTapGesture or Click event not setting values ?. Bug or issue with way .sheet works?
SWIFTUI List object .onTapGesture or Click event not setting values ?. Bug or issue with way .sheet works? On list object .onTapGesture / selection of the row I wanted send the Index /value to another view via .Sheet option And 90% of the time I get 0 (wrong value) help / guide , a newbie Code snippets for main view & popup view below //Main view with list object: import SwiftUI struct SwiftUIView_Sheet_Test_Main: View { let workflow_trn_data:[workflow_transaction_data] = [ .init(mst_rec_id: 100, work_task: Task 100), .init(mst_rec_id: 101, work_task: Task 101) ] @State private var selected_Mst_record:Int32 = 0 @State private var isPopupSheetActive:Bool = false var body: some View { Text(Sheet Test Main View) NavigationStack{ List() { ForEach(0..
Topic: UI Frameworks SubTopic: SwiftUI
2
0
269
Jul ’25
Reply to Calling Async Functions in SwiftUI
Use the task(priority:_:) modifier. It allows you to perform an asynchronous task with a lifetime that matches that of the view. Discover concurrency in SwiftUI dives deep into how you can use Swift's concurrency features in your SwiftUI app. It's a great resource you should review.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’25
Reply to How do I add an "insert" feature like UITableViewCell.EditingStyle in SwiftUI?
I'm not sure if there's a built-in way of doing it, but you can add swipeActions to a row, then perform an action based on the button tapped. var body: some View { List { ForEach(etc.) { element in RowView(rowData: element) .swipeActions(edge: .leading, allowsFullSwipe: false) { MySwipeButtonsView(rowData: element) } } } } struct MySwipeButtonsView: View { var rowData: RowDetails // The type for the row data var body: some View { Button { insertRow() // Insert a row above/below in your array, and SwiftUI should redraw the list if you've set up an observable model etc. } label: { Label(, systemImage: plus) .symbolRenderingMode(.palette) .labelStyle(.iconOnly) .tint(Color.green) .foregroundStyle(Color.white) } } }
Topic: UI Frameworks SubTopic: SwiftUI
Feb ’25
Reply to Entire view re-renders when updating dictionary
This would depend on how you manage dependcies in your View. You would want to structure your view so that it depends on only the data it needs to display and not your entire dictionary. This is because Views form a graph and SwiftUI looks at depencies when evaulating a code. I would suggest you checkout Demystify SwiftUI performance session, it dives into how SwiftUI evaluates your views.
Topic: UI Frameworks SubTopic: SwiftUI
Mar ’25