Avatar
正解がわからない ↓のコードで以下のように出力されるのは正しい? 100 200 300 300 import Foundation actor BankAccount { var balance = 0 func deposit(_ amount: Int) -> Int { balance += amount Thread.sleep(forTimeInterval: 1.0) return balance } func getInterest(with rate: Double) -> Int { let newBalance = Double(balance) * (1.0 + rate) return Int(newBalance) } } func bankAccountMain() { let bankAccount = BankAccount() Task.detached { print(Thread.current) print(await bankAccount.deposit(100)) print(await bankAccount.getInterest(with: 0.5)) } Task { print(Thread.current) print(await bankAccount.deposit(100)) print(await bankAccount.getInterest(with: 0.5)) } } (edited)