3

i am trying to execute a simple code in SwiftUI but it shows error: Execution was interrupted, reason: signal SIGABRT. here is a code `

struct ContentView: View {

    let data = (1...100).map { "Item \($0)" }

    let columns = [
        GridItem(.adaptive(minimum: 80))
    ]
    var body: some View {
        ScrollView {
            LazyVGrid(columns: columns, spacing: 20) {
                ForEach(data, id: \.self) { item in
                    Text(item)
                }
            }
            .padding(.horizontal)
        }
        .frame(maxHeight: 300)
    }
}
NicolasElPapu
  • 1,612
  • 2
  • 11
  • 26

1 Answers1

6

It seems there is a bug with (at least this version) of Playground, when using ForEach. I have the same issue and you can find more details in the CrashLogs of console

Check crashing playground with ForEach

Workarround

  • Move ContentView to a separate file in Sources of Playground
  • Don't forget the public modifiers

public struct ContentView: View {

    let data = (1...100).map { "Item \($0)" }

    let columns = [
        GridItem(.adaptive(minimum: 80))
    ]
    
    public init() {}
    
    public var body: some View {
        ScrollView {
            LazyVGrid(columns: columns, spacing: 20) {
                ForEach(data, id: \.self) { item in
                    Text(item)
                }
            }
            .padding(.horizontal)
        }
        .frame(maxHeight: 300)
    }
}
Daniel Marx
  • 676
  • 5
  • 8
  • great workaround thanks , i hope they fix it in Xcode 12.5 . – Omar Ghanem Apr 16 '21 at 20:49
  • It helped on my side but didn't solve it entirely, the view is staying up a couple of seconds... playground version: Version 3.4.1 (1302.34) – herve Sep 23 '21 at 07:57
  • and then? Out of curiosity 3.4.1 (1302.34) is the Playground App for iPad? or you are using the Playgrounds from Xcode? – Daniel Marx Sep 24 '21 at 09:01