Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobsapps/ebe4358f25b78c5ee71043333dd6be19 to your computer and use it in GitHub Desktop.
Save jacobsapps/ebe4358f25b78c5ee71043333dd6be19 to your computer and use it in GitHub Desktop.
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