无法将'String'类型的值转换为预期的参数类型'(name:String,balance:Double)'

时间:2015-12-03 00:55:46

标签: string swift syntax-error

在下面的代码中,我试图弄清楚为什么最后的两行显示为错误。

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)

1 个答案:

答案 0 :(得分:1)

你前两行没有平衡。您将金额作为名称的一部分。试试这个:

var account1 = ("State bank personal", 1011.10)
var account2 = ("State bank business", 24309.63)