Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

Edit data within a list in SwiftUI
I think I messed something up because except the default values, I cannot see anything in my list. I want to have a TextField and a Counter in my list per entry which should be editable the whole time. But also the preview just yields the default values and not the ones I set preemptively in my preview construct. Changes in runtime are just ignored. This is what I got so far, did I maybe messed up @State, @Binding and @ObservedObject again? Or did I missed something else? If I search for edit in swiftui list all I get is the EditButton solution which is not what I want. Sourcecode - https://developer.apple.com/forums/content/attachment/70b85477-f66c-4423-90bf-a1d073c2646c
3
0
3.4k
Jul ’20
SwiftUI List misaligned with title bar.
Hello! I am making an app in SwiftUI and find it hard to make good-looking UIs with SwiftUI when using the List. When having a big navigation bar, the list appears misaligned with the title. This is a preview within Xcode. Don't know if that changes anything 🤷. Below is the code. I should note I am using Xcode 16 beta 3. // // SwiftUIView.swift // import SwiftUI struct SwiftUIView: View { struct D { var id: Int var name: String var identifier: String } let items: [(Int, D)] = [ (0, D(id: 0, name: Test One, identifier: one.example.test)), (1, D(id: 1, name: Test One, identifier: two.example.test)), (2, D(id: 2, name: Test One, identifier: three.example.test)), (3, D(id: 3, name: Test One, identifier: four.example.test)) ] var body: some View { NavigationStack { List(items, id: .1.id) { idx, d in VStack(alignment: .leading) { Text(d.name) .bold() Text(d.identifier) } } .navigationTitle(Hello Title) } } } #Preview { SwiftUIView() }
3
0
820
Jul ’24
Dose List in SwiftUI reuse itself while scrolling?
I am a beginner in SwiftUI. I try to find some new way to build a page same as UITableView. Some said that List does reuse its cell, but I tried these following code than make the app so laggy. So, the only way to interacting TableView is use representable ? struct TestView: View { var body: some View { NavigationView { List { ForEach(0..<1000000, id: .self) { key in Text((key)) } } } } }
0
0
478
Mar ’23
SwiftUI List reload causes crash
I get a crash when reloading a List based on some search results. The results may change out the sections and rows. The error returned looks like an internal error because sometimes it works and sometimes it crashes on the same search string.Error:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt to create two animations for cell' *** First throw call stack: ( 0 CoreFoundation 0x00007fff23afdbde __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff5015cb20 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23afd958 +[NSException raise:format:arguments:] + 88 3 Foundation 0x00007fff255506f5 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191 4 UIKitCore 0x00007fff47134191 -[_UITableViewUpdateSupport(Private) _setupAnimationsForNewlyInsertedCells] + 1575 5 UIKitCore 0x00007fff4713ef73 -[_UITableViewUpdateSupport _setupAnimations] + 118 6 UIKitCore 0x00007fff470d5ec4 -[UITableView _updateWithItems:updateSupport:] + 2883
3
0
5.5k
Sep ’19
SwiftUI AnyView performance when used at screen boundaries
After watching this years Demystifying SwiftUI session I revisited my project for usage of AnyView. A common pattern that I used was using AnyView at the screen boundary to allow dynamic routing. Screen boundaries are for me new views that are modally presented or pushed in navigation stacks for example. So a common pattern in my code base looks like this class FooPresenter { @Published var isPresenting = false @Published var presentedView: AnyView } struct FooView { @StateObject var presenter = FooPresenter() var body: some View { Text(hello) .sheet(isPresented: $presenter.isPresenting) { presenter.presentedView } } } Now I understand that SwiftUI uses the type system to diff views, animate and more. And I can fully understand that on a single screen it is advisable to use as few AnyViews as possible. However I am wondering is there a performance difference when using it across screen boundaries? Furthermore, is the SwiftUI system resetting its type data at AnyView and the
0
0
1.3k
Jun ’21
Working of List and ForEach in SwiftUI
What’s the difference if we write

 myArray is a object of strict which has only two items An id and name List(self.myArray, id: .id) { currentArray in
 .... 
}

 And 


List {
 ForEach(self.myArray, id: .id) { currentArray in
 ......
 }
 }
3
0
6.5k
Jun ’20
SwiftUI List rows loaded all at once
When using a simple SwiftUI List, the rows will be loaded lazy (not all at once) BUT: When having a ViewBuilder in place for each Row in the List all views are loaded at once (not lazy) Something like @ViewBuilder var content: some View { switch building.kind { case .condo: Text(Condo (building.index)) case .house: Text(House (building.index)) case .warehouse: Text(Warehouse (building.index)) } } Is this behavior correct and intended ?
4
0
383
Aug ’24
How to customise or remove separators from List in SwiftUI
I have a List in my SwiftUI view in order to present a presumably long list of cells. My designers want table separators to have custom length and colour. Previously I’ve had a dirty hack to hide default separators completely (modified UITableView.appearance() separator-related values) which does not seem to work on iOS 14. I’ve thought of using .listStyle(...) with custom ListStyle but the protocol stubs for this protocol look really scary. Is there some normal way to modify separators in List? Or is the preferable way on iOS 14 for this kind of layout would be one-column LazyVGrid inside a ScrollView?
4
0
5.3k
Jun ’20
Drag drop nested list in swiftui
Hi, I managed to have a nested list in swiftui 3 (with foreach) and drag and drop to reorder the list when I enter the built-in edit mode. Problems / limitation when dragging / dropping a list item from edit mode: I can't change its nesting level: for example, if I drag an item that is 3 nested levels deep, I can't seem to be able to drop it on let's say level 1. When an item has children, and they are expanded, if I drag the father, the children will not follow. I can't drag from one section, and drop on another. What are the solutions to circumvent those problems? Is there built-in way to do it, if not, is it even possible without resorting to UIKit?
1
0
1.7k
Jan ’22
Clarification on SwiftUI Environment Write Performance
I'm looking for clarification on a SwiftUI performance point mentioned in the recent Optimize your app's speed and efficiency | Meet with Apple video. (YouTube link not allowed, but the video is available on the Apple Developer channel.) At the 1:48:50 mark, the presenter says: Writing a value to the Environment doesn't only affect the views that read the key you're updating. It updates any view that reads from any Environment key. [abbreviated quote] That statement seems like a big deal if your app relies heavily on Environment values. Context I'm building a macOS application with a traditional three-panel layout. At any given time, there are many views on screen, plus others that exist in the hierarchy but are currently hidden (for example, views inside tab views or collapsed splitters). Nearly every major view reads something from the environment—often an @Observable object that acts as a service or provider. However, there are a few relatively small values that are written to the environ
4
0
1.3k
Nov ’25
SwiftUI 4: Set list background color
In SwiftUI 3 we used the following code snippet to set the background color of a list. struct ContentView: View { var body: some View { List { Text(Hello World!) } .onAppear { // Placed here for sample purposes, normally set globally UITableView.appearance().backgroundColor = .clear } .listStyle(.insetGrouped) .background(Color.red) } } This is not working anymore in SwiftUI 4 (FB10225556) as the List is not based on UITableView anymore. Any workaround ideas?
8
0
11k
Jun ’22
How to pass data from a TextField to a List (SwiftUI)
I have an app I'm working on where you make little digital ID cards with four pieces of data that I need to pass from a TextField to a List: Your Name (name) Your ID for Card (id) QR Code or Barcode? (qrcode Toggle) Card Name (cname) This is my CardsView: import SwiftUI struct Card: Identifiable { let id = UUID() let title: String } struct CardsView: View { @State private var editMode = EditMode.inactive @State private var cards: [Card] = [] private static var count = 0 var body: some View { NavigationView { List { ForEach(cards) { cards in NavigationLink(destination: CardFullView(cname: Moore Lunch)) { CardRow(cname: Lunch, name: John Doe, id: 123456) } } .onDelete(perform: onDelete) .onMove(perform: onMove) } .navigationTitle(Cards) .toolbar { ToolbarItem(placement: .navigationBarLeading) { EditButton() } ToolbarItem(placement: .navigationBarTrailing) { NavigationLink( destination: AddView(), label: { Image(systemName: plus) }) } } .environment(.editMode, $editMo
21
0
3.8k
Dec ’20
All Item Row Positions After List onMove(perform:)
Using List to list an array of an object isn't a problem. For example, I have simple lines of code below to list an array of some guy. struct ContentView: View { @State private var selectedFieldItem: FieldItem? private var fieldListView: some View { List(selection: $selectedFieldItem) { ForEach(fieldItems.indices, id: .self) { index in Button { ... } label: { let fieldItem = fieldItems[index] HStack(spacing: 10) { Text((fieldItem.name)) } .frame(maxWidth: .infinity, alignment: .leading) } .buttonStyle(.borderless) } .onMove(perform: fieldlocate) } .listStyle(.plain) } private func fieldlocate(from source: IndexSet, to destination: Int) { fieldItems.move(fromOffsets: source, toOffset: destination) } } As you see in the picture below, I can move a row up and down. A problem that I now have with List is that I cannot know how those rows are rearranged after one of them is moved up or down. In Cocoa, you can tell the positions of all rows after one moves with
Topic: UI Frameworks SubTopic: SwiftUI
1
0
416
Aug ’24
MacOS SwiftUI List move multiple rows
Hi, I have this simple view in SwiftUI, where it's possible to move a single row and select one or more rows. struct ContentView: View { @State var selectedItems = Set<Int>() @State var items = Array(1...10).map({ S(id: $0) }) var body: some View { List(selection: $selectedItems) { ForEach(items) { (item) in Text(String(item.id)) .padding() } .onMove(perform: { indices, newOffset in withAnimation { self.items.move(fromOffsets: indices, toOffset: newOffset) } }) } } } When I select 2 or more rows and try to move them I got this error log: 2020-07-30 10:20:03.035238+0200 list[54240:1678921] [General] There are 2 items on the pasteboard, but 1 drag images. There must be 1 draggingItem per pasteboardItem. 2020-07-30 10:20:03.039250+0200 list[54240:1678921] [General] ( 0 CoreFoundation 0x00007fff2a8865af __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff6acb36c4 objc_exception_throw + 48 2 CoreFoundation 0x00007fff2a886413 +[NSException raise:format:] + 189
2
0
1.9k
Jul ’20
TabularData Framework: DataFrame as a List in SwiftUI
The new TabularData framework in iOS 15, MacOS 12 and watchOS 8 opens up opportunities for easier, more efficient ingestion of data (and for ML possibilities). However, it does not appear to be possible to directly use a DataFrame's rows for a List or ForEach in SwiftUI: the compiler gives an error that the rows do not conform to RandomAccessCollection Protocol. The documentation for Rows does not state compliance with such, even through there are methods which inherit from the protocol. Using a separate iteration to extract each Row (as a DataFrame.Row) from the DataFrame into a new array works. I make this array identifiable by using the row.index as the id. However, if the DataFrame is large this adds considerably to storage and processing overheads. Any thoughts on directly using the DataFrame's Rows in SwiftUI?
2
0
3.2k
Jun ’21