SwiftUI macOS Preview Crash When Using Custom Row Directly Inside List

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?
Answered by Developer Tools Engineer in 861657022

Hi,

Sorry to hear you are having problems getting previews working. You are hitting a known issue with xcode previews and usage of Lists on macOS.

So far we have no better workaround to offer then what you've identified.

Accepted Answer

Hi,

Sorry to hear you are having problems getting previews working. You are hitting a known issue with xcode previews and usage of Lists on macOS.

So far we have no better workaround to offer then what you've identified.

Any update on this? I am having the same issue.

In my case the view is a little bit more complex, so I cannot use ZStack: It will stack every row on top of each other, so they are overlayed. Using a VStack(spacing: 0) causes problems with the List-selection.

Hello @joachim_me

If you file a bug report for this issue, you can track the status of this report. I'm curious to see if there's any updates as well, but no feedback report was shared in this thread.

Create a report using Feedback Assistant, and reply with the feedback number when complete.

Thank you,

 Travis

SwiftUI macOS Preview Crash When Using Custom Row Directly Inside List
 
 
Q