I’ve hit a strange SwiftUI preview crash that happens on macOS previews when using a view inside a List’s ForEach, resulting in the error Fatal Error in TableViewListCore_Mac2.swift.
Only crashes macOS preview - iPhone/iPad preview doesn't crash.
Doesn't crash when actually running the app.
Here’s a minimal reproducible example, causing the preview to crash.
XCode: Version 26.0.1 (17A400)
MacOS: 26.0.1 (25A362)
import SwiftUI
struct Item: Identifiable {
let id = UUID()
let name: String
}
struct ItemRow: View {
let item: Item
var body: some View {
HStack {
Button(action: {}) { Image(systemName: "play") }
Text(item.name)
Spacer()
ProgressView()
}
}
}
struct ContentView: View {
@State private var items = [
Item(name: "Item A"),
Item(name: "Item B"),
]
var body: some View {
List {
ForEach(items) { item in
ItemRow(item: item)
}
}
}
}
#Preview("Content view") {
ContentView()
}
#Preview("Item row") {
ItemRow(item: Item(name: "Item A"))
}
If I wrap the row in a container, like this:
ForEach(items) { item in
ZStack {
ItemRow(item: item)
}
}
the crash seems to disappear.
Has anyone else seen this behavior?
What might I be doing wrong?
Any ideas about what could be causing this?
Xcode Previews
RSS for tagCreate an app UI and configure almost everything your users see using Xcode Previews.
Posts under Xcode Previews tag
81 Posts
Selecting any option will automatically load the page