Slide 6
Slide 6 text
let dict = NSMutableDictionary(contentsOfFile: "account.plist") ?? NSMutableDictionary()
let fund = dict["fund"] as? Int ?? 100
var account = Account(fund: fund)
do {
try account.withdraw(amount)
dict["fund"] = account.fund
dict.writeToFile("account.plist", atomically: true)
} catch Account.Error.NonPositiveTransactionNotAllowed(let amount) {
print("Amount (\(amount)) must be positive.")
} catch Account.Error.TransactionExceedsFunds {
print("Amount exceeds account balance (\(account.fund)).")
} catch {
print("An unexpected error <\(error)> occured.")
}