Search results for

SwiftUI List performance

50,605 results found

Post

Replies

Boosts

Views

Activity

SwiftUI List crashing when adding items and selecting on macOS
Hi all, I've been experiencing some issues using SwiftUI's List on macOS Monterey and macOS Ventura Beta 3, where my app will lock up with an error if I add and select items at the same time: NSOutlineView error inserting child indexes [number of indexes: 1 (in 1 ranges), indexes: (10)] in parent 0x0 (which has 9 children). Minimal Reproducible Example // Built with Xcode 14 Beta 3 struct MyData: Identifiable { let id = UUID() var text: String } struct ContentView: View { @State var data: [MyData] = [] @State var selection = Set() var body: some View { NavigationView { List(data, selection: $selection) { item in Text(item.text) } Button(Press Me!) { DispatchQueue(label: Worker).async { for i in 0..<500 { DispatchQueue.main.async { data.append(MyData(text: String(i))) } usleep(100_000) // 0.1 seconds } } } } } } As you can see, the app is just an empty Sidebar. When you press the button, a worker thread starts and it adds a new item to the Sidebar every 0.1 seconds (protected by D
0
0
768
Jul ’22
Reply to SwiftUI vs Flutter for Embedding Unity in an iOS App?
Hello, We're unable to provide insight into using Flutter; however given what you're building, using SwiftUI with our Unity plugins is expected to be performant while providing the most direct way to interact with iOS features. Again, we can't speak on behalf of Flutter but can say that our Unity plugins are well maintained and that isn't expected to change. Another benefit of SwiftUI is more straightforward performance profiling with Instruments and Metal Tools i.e. it will be easier to understand how SwiftUI is performing than interpreting Flutter's runtime performance characteristics.
Topic: Community SubTopic: Apple Developers Tags:
Jul ’25
Xcode 16 SwiftUI List Fast Scrolling Issue
Hi! When building my app using Xcode 16, fast scrolling (using scrollViewProxy.scrollTo) a list would result in items not appearing even when scrolling stopped. This does not happen when the app is built with Xcode 15, even on iOS 18. I'm also getting this error in the logs: List failed to visit cell content, returning an empty cell. - SwiftUICore/Logging.swift:84 - please file a bug report.
5
0
1.4k
Sep ’24
Arabic Text Appears Reversed and Broken in SwiftUI Lists, TextFields, and Pickers
Hello, I would like to report a critical issue with Arabic text rendering in SwiftUI apps on iOS and iPadOS. When using Arabic as the default language (Right-to-Left - RTL), Arabic text appears reversed and disconnected inside several SwiftUI components like: List Section TextField Picker Custom views (like StudentRowView) Even though the environment is set to .layoutDirection(.rightToLeft), the dynamic Arabic text is not rendered properly. Static headers display correctly, but any dynamic content (student names, notes, field titles) becomes broken and unreadable. Examples where the issue occurs: AboutView.swift → Arabic text inside List and Section SettingsView.swift → TextField placeholders and Picker options StudentRowView.swift → Student names and grade field titles Environment: SwiftUI 5 (Xcode 15+) iOS 17+ Reproducible 100% on both Simulator and real devices. Expected Behavior: Arabic text should appear properly connected, right-aligned, and readable without
1
0
151
Apr ’25
SwiftUI List wrong behavior on click on cell with Magic Trackpad
Hello, I am experiencing a weird issue on iPadPro (12.9 running iOS 14.4) and I would like to know if there is any workaround or (in case it's a bug) any plan to fix this in a future version. I have a list of items in SwiftUI, when I tap with my finger on it, it fire the onTapGesture callback. Everything as expected. However, when I use my Magic Trackpad on my iPad, first click on an item in my list doesn't fire any callback, a second click on the same cell will. I need to double click on a cell to be able to select it, and after investigation, double click with my Magic Trackpad on a cell will only fire a one tap event (if I specify 2 callbacks, one with 1 tap and another one with 2 taps, only the 1 tap callback will be triggered when clicking 2 times, if I click 3 times, 2 taps event will be triggered, and so on). Does someone else get this behavior? Am I missing something? Or is it a bug Apple is aware of? Do you have any workaround? Best, Serge
0
0
780
Mar ’21
SwiftUI List/Form Header Alignment on iOS 15?
Hi there, With the following code on iOS 15, the header text is aligned with the text within the List or Form: Form { Section { Text(Hello, world!) } header: { Text(Section Header).sectionHeaderStyle() } } .listStyle(InsetGroupedListStyle()) //... public extension Text { func sectionHeaderStyle() -> some View { self .font(.system(.title3)) .fontWeight(.bold) .foregroundColor(.primary) .textCase(nil) } } However, back on iOS 14, the analogous code aligns the header with the List Section itself: Form { Section(header: Text(Section Header).sectionHeaderStyle()) { Text(Hello, world!) } } .listStyle(InsetGroupedListStyle()) Does anyone know how to get the iOS 14 behavior of aligning the section header with the List Section itself, and not aligning with the text within the Section?
2
0
7.1k
Jul ’21
How we can use alert menu before delete list items in SwiftUI?
I have list items in SwiftUI, and when I delete list items, but when I click the delete button, it delete item randomly, I want to delete seleted item, where is the mistake? struct MyView: View { @State private var selectedUsers: MyModel? @State var datas: [MyModel] @State private var confirmDelete = false var body: some View { ScrollView(.vertical, showsIndicators: false, content: { VStack(content: { ForEach(datas){ data in MyRowView(data: data) .contextMenu { Button(action: { self.delete(item: data) }) { Text(delete) } } .onTapGesture { selectedUsers = data } .confirmationDialog( Are you sure ?, isPresented: $confirmDelete, titleVisibility: .visible ){ Button(role: .destructive) { self.delete(item: data) } label: { Text(ok) } Button(role: .cancel) { } label: { Text(cancel) } } } .onDelete { (indexSet) in self.datas.remove(atOffsets: indexSet) }}) })} private func delete(item data: MyModel) { if let index = datas.firstIndex(where: { $0.id == data.id }) { datas.remove(at: index) } }
1
0
1.1k
Feb ’22
SwiftUI Hierarchical List on macOS represents incorrect results.
A item is replaced by the last uncle. Conditions are: Target to macOS The item X is placed next to the folded sibling with children. The parent of the X is not the last sibling. The last uncle Y has no children. then, X will be replaced by Y, and Y appears twice. It's amazing that the very fundamental operations are broken. As this issue only occurs on macOS, it is not reproduced on playground preview or iOS. import SwiftUI struct TreeViewTest: View { var items: [Item] var body: some View { List( items, children: .children ) { item in Text(item.id) } } struct Item: Hashable, Identifiable { var id: String var children: [Self]? } } struct TreeViewTest_Previews: PreviewProvider { static var previews: some View { TreeViewTest(items: [ .init(id: 0, children: [ .init(id: 00), .init(id: 01, children: [ .init(id: 010), .init(id: 011), .init(id: 012) ]), .init(id: 02), .init(id: 03) ]), .init(id: 1) ]) } } It represents: 0 -00 +01 -1 /* <- should be 02 */ -03 1 Is there anything wrong with my code
1
0
943
Nov ’20
SwiftUI: Change List row Highlight colour when tapped
The default colour of a list row when tapped is grey. I try many solution on stackoverflow and apple form, I did not solve problem, any idea? RecentRowView: struct RecentRowView: View { var body: some View { HStack(spacing: 15){ List{ NavigationLink(destination: SecondView() ){ VStack{ HStack{ VStack(alignment: .leading, spacing: 8, content: { Text(recent.name) .font(.custom(Helvetica Neue, size: 14)) }) Spacer(minLength: 10) ZStack { } } } } } } } }
1
0
4k
Jul ’21
How do I move list items between sections in SwiftUI while adding the new section and removing the old
I have a dataset(each piece has a string and an int) that I'm breaking into sections in a SwiftUI list. When the user enters the search field, I want to completely change the sections in the list, but animate the list items to the new section. I've done this in UIKit as seen in the first video below. However, as I'm testing out SwiftUI in iOS14, I notice that when I change between the sets of sections, the items in the list don't move vertically to the new section, but rather animate it left to right with the new section. When used with the large dataset it makes the entire screen look as if it is animating in from the left. How can we disable the section animation, or change it to behave similarly to the UIKit method. Is there another way to handle this more effectively? I've included two SwiftUI demos showing animation issues with items in a list moving between sections. In the first one, it moves the data from sections 1A and 2A to 1B
3
0
1.7k
Aug ’20
SwiftUI List insertion changes aren't animated on macOS 15
I've been struggling with this issue since the release of macOS 15 Sequoia. I'm wondering if anyone else has encountered it or if anyone has a workaround to fix it. Inserting a new element into the array that acts as data source for a SwiftUI List with a ForEach is never animated even if the insertion is wrapped in a withAnimation() call. It seems that some other changes can be automated though: e.g. calls to shuffle() on the array successfully animate the changes. This used to work fine on macOS 14, but stopped working on macOS 15. I created a very simple project to reproduce the issue: import SwiftUI @main struct TestApp: App { var body: some Scene { WindowGroup { ContentView() } } } struct IdentifiableItem: Identifiable { let id = UUID() var name: String { Item (id) } } struct ContentView: View { @State var items: [IdentifiableItem] = [ IdentifiableItem(), IdentifiableItem(), IdentifiableItem(), IdentifiableItem(), IdentifiableItem(), IdentifiableItem(), IdentifiableItem(), Ident
3
0
654
Oct ’24
Failed to produce diagnostic for expression when creating a list view in SwiftUI
Hello! I am new to SwiftUI. Recently I am trying to create a list view for my app. However, when I add the list view using ForEach, an error will show up saying Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project. When I comment out the ForEach, everything back to normal. I have no idea what is wrong to the code. Hope someone can help me out! Thank you! The code throw error: Swift struct PlaylistDetailView: View { var playlist: Playlist var body: some View { NavigationView{ VStack{ if playlist.songs.count == 0 { Text(No Songs) } else{ Text(Have Songs) List{ ForEach(playlist.songs){ item in SongRow(song: item) } } } } .navigationTitle(playlist.name) .navigationBarTitleDisplayMode(.inline) .toolbar(content: { ToolbarItem(placement: .navigationBarLeading) { Button(action: {}, label: { Text(Edit) }) } ToolbarItem(placement: .navigationBarTrailing) { Button(action: {}, label: { Image(sys
2
0
682
May ’21
Sorted SwiftUI List Crashes iOS 14.2 App
Ran into a challenging EXC_BAD_ACCESS iOS app crash that provides no real information on the culprit within my code. Tried Zombie Objects to no avail. After some extensive trial and error, the issue seems to point to using a sorted and sectioned SwiftUI List pulled from a CoreData FetchRequest. If I change from a List to a ScrollView/VStack, things work just fine without any other code changes. (Obviously not preferred since I'll lose native swipe-to-delete, etc). Using the same List code, the issue didn't exist in iOS 13 nor did it seem to exist in earlier iOS 14 versions. Some code snippets below showing how I'm handing the FetchRequest, Sort/Sectioning by date, and ultimate display. Also included a snippet of the crash log. If anyone's run into a similar issue or has some insight, it would be appreciated. Wondering if the true root cause is an OS-level bug since the problem didn't exist before. Fetch Request: @FetchRequest(entity: StoredTrip.entity(), sortDescriptors: [
0
0
1.2k
Nov ’20
SwiftUI - List multi selection move / reorder (works on Mac but not on iOS)
How can I enable multi-select and then move / reorder selected items in a List with ForEach (in SwiftUI)? I tried the following code. On Mac it works fine - it allows me to select multiple items, and then drag them all together to another place in the list. On iOS it allows me to move individual items with drag-and-drop, and allows me to enter Edit mode to select multiple items but when I try to move the selected items with drag-and-drop, they can be dragged but they can't be dropped elsewhere in the list: struct ExampleListView: View { @State var items = [Dave, Tom, Jeremy, Luke, Phil] @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: move) } .navigationBarItems(trailing: EditButton()) } } func move(from source: IndexSet, to destination: Int) { items.move(fromOffsets: source, toOffset: destination) } } This code has the
1
0
1.5k
Mar ’24