Created
July 4, 2025 13:46
-
-
Save jacobsapps/ebe4358f25b78c5ee71043333dd6be19 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
class BankAccount { | |
enum BankAccountError: Error { | |
case insufficientFunds | |
} | |
private(set) var balance: Double = 0 | |
func deposit(_ amount: Double) { | |
balance += amount | |
} | |
func withdraw(_ amount: Double) throws(BankAccountError) { | |
guard balance >= amount else { | |
throw .insufficientFunds | |
} | |
// multiple threads mutating this may cause a data race, | |
// therefore crashing or data corruption is likely | |
balance -= amount | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment