Last active
September 24, 2025 12:38
-
-
Save pookjw/1086aba905ccdda431188e501a2bc81b to your computer and use it in GitHub Desktop.
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 | |
| @globalActor | |
| actor MyActor { | |
| let queue = DispatchSerialQueue(label: "Test") | |
| nonisolated var unownedExecutor: UnownedSerialExecutor { queue.asUnownedSerialExecutor() } | |
| static let shared = MyActor() | |
| var count: Int = 0 | |
| func binding() -> Binding<Int> { | |
| Binding { | |
| return self.count | |
| } set: { newValue in | |
| MainActor.assertIsolated() // ??? | |
| print(newValue) | |
| self.count = newValue | |
| } | |
| } | |
| } | |
| struct ContentView: View { | |
| @State private var binding: Binding<Int>? | |
| var body: some View { | |
| Group { | |
| if let binding { | |
| ChildView(count: binding) | |
| } else { | |
| Color.clear | |
| } | |
| } | |
| .task { | |
| binding = await MyActor.shared.binding() | |
| } | |
| } | |
| } | |
| struct ChildView: View { | |
| @Binding private var count: Int | |
| init(count: Binding<Int>) { | |
| _count = count | |
| } | |
| var body: some View { | |
| Button("Trigger") { | |
| count += 1 | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment