Skip to content

Instantly share code, notes, and snippets.

@krzysztofzablocki
Last active December 11, 2023 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzysztofzablocki/61ede7491b1875e86cbe3a843352c6f4 to your computer and use it in GitHub Desktop.
Save krzysztofzablocki/61ede7491b1875e86cbe3a843352c6f4 to your computer and use it in GitHub Desktop.
Breaking isolation context bug
import SwiftUI
@Observable @MainActor
final class ViewModel {
var name: String { "Foo" }
}
class ObservableFoo: ObservableObject {}
struct ContentView: View {
@Bindable var viewModel: ViewModel
// Comment this out to see the error pop up when accessing the `viewModel.name`
// property. (whether it's properly injected on just like this does not matter)
@ObservedObject private var foo = ObservableFoo()
var body: some View {
VStack {
Text(text)
}
.padding()
}
private var text: String {
viewModel.name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment