Created
November 15, 2024 09:15
-
-
Save keeshux/4a963cdebb1b577b87b08660ce9d3364 to your computer and use it in GitHub Desktop.
TableColumn crashing due to EnvironmentObject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discussion here:
https://developer.apple.com/forums/thread/768828