Created
December 5, 2024 16:12
-
-
Save VAndrJ/ae9be3406cc960848383bafdc4b75731 to your computer and use it in GitHub Desktop.
Swift 6 actor deinit issue.
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 | |
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