Skip to content

Instantly share code, notes, and snippets.

@pookjw
Last active September 24, 2025 12:38
Show Gist options
  • Select an option

  • Save pookjw/1086aba905ccdda431188e501a2bc81b to your computer and use it in GitHub Desktop.

Select an option

Save pookjw/1086aba905ccdda431188e501a2bc81b to your computer and use it in GitHub Desktop.
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