Skip to content

Instantly share code, notes, and snippets.

@keeshux
Created November 15, 2024 09:15
Show Gist options
  • Save keeshux/4a963cdebb1b577b87b08660ce9d3364 to your computer and use it in GitHub Desktop.
Save keeshux/4a963cdebb1b577b87b08660ce9d3364 to your computer and use it in GitHub Desktop.
TableColumn crashing due to EnvironmentObject
import SwiftUI
public struct TableCrashView: View {
@StateObject
private var someObject = SomeObject()
public init() {
}
public var body: some View {
NavigationStack {
SomeTableView()
.environmentObject(someObject)
}
}
}
// MARK: - Model
@MainActor
final class SomeObject: ObservableObject {
let foobar = "FooBar"
}
struct Model: Identifiable {
let id = UUID()
let content: String
}
// MARK: - Views
struct SomeTableView: View {
@EnvironmentObject
private var someObject: SomeObject
@State
private var data: [Model] = Array(repeating: Model(content: "FOOBAR"), count: 1000)
public init() {
}
public var body: some View {
Table(data) {
TableColumn("Content") {
SomeColumnView(model: $0)
// .environmentObject(someObject)
// macOS crashes consistently without redoing .environmentObject()
// iOS works fine
}
}
}
}
struct SomeColumnView: View {
@EnvironmentObject
private var someObject: SomeObject
let model: Model
var body: some View {
Text("\(model.content) - \(someObject.foobar)")
}
}
@keeshux
Copy link
Author

keeshux commented Nov 15, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment