1
在下面的代碼中,我想弄清楚爲什麼最後2行顯示爲錯誤。不能將類型'字符串'的值轉換爲期望的參數類型'(名稱:字符串,餘額:雙)'
var account1 = ("State bank personal, 1011.10")
var account2 = ("State bank business, 24309.63")
func deposit(amount : Double, account : (name : String, balance : Double)) -> (String, Double) {
let newBalance : Double = account.balance + amount
return (account.name, newBalance)
}
func withdraw(amount : Double, account : (name : String, balance : Double)) -> (String, Double) {
let newBalance : Double = account.balance - amount
return (account.name, newBalance)
}
var mondayTransaction = deposit
var fridayTransaction = withdraw
let mondayBalance = mondayTransaction(300.0, account1)
let fridayBalace = fridayTransaction(1200.0, account2)