Skip to content

Instantly share code, notes, and snippets.

@VAndrJ
Created December 5, 2024 16:12
Show Gist options
  • Save VAndrJ/ae9be3406cc960848383bafdc4b75731 to your computer and use it in GitHub Desktop.
Save VAndrJ/ae9be3406cc960848383bafdc4b75731 to your computer and use it in GitHub Desktop.
Swift 6 actor deinit issue.
import SwiftUI
struct ContentView: View {
var body: some View {
Button("increment") {
Task {
await CountActor.shared.increment()
}
}
}
}
actor CountActor {
static let shared = CountActor()
var count = 0
func increment() {
Task { [unowned self] in
try? await Task.sleep(for: .milliseconds(100))
count += 1
print("Count:", count)
}
}
deinit {
print(#function)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment