如何从我的函数中的Struct访问此值?迅速

时间:2015-03-13 22:50:25

标签: swift

我希望能够传递garrett或allegany,并调用其中一个值,但我使用的点符号给我mdCounties.type没有名为County transfer的成员。但我确实创建了一个实例(garrett和allegany)???

  struct mdCounties {
    var countyRecordation: Double = 0
    var countyTransfer: Double = 0
}

let garrett = mdCounties(countyRecordation: 7.0, countyTransfer: 1.0)
let allegany = mdCounties(countyRecordation: 6.50, countyTransfer: 0.005)

func mDtransferTaxCalc(purchasePrice: Double, split: Bool,mdCounties) -> Double {
    let userCountyTransfer = (purchasePrice) * mdCounties.countyTransfer

2 个答案:

答案 0 :(得分:1)

mdCounties是你的类型。您需要结构的实例来访问其实例方法。您也没有正确编写函数参数。这样做:

func mDtransferTaxCalc(purchasePrice: Double, split: Bool, counties: mdCounties) -> Double {
    let userCountyTransfer = (purchasePrice) * counties.countyTransfer
    return userCountyTransfer
}

答案 1 :(得分:0)

在mDtransferTaxCalc参数列表中,为mdCounties参数指定名称,并在方法中使用该名称。

    func mDtransferTaxCalc(purchasePrice: Double, split: Bool, county: mdCounties) -> Double {
let userCountyTransfer = purchasePrice * county.countyTransfer
}