我希望能够传入 garrett 或 allegany,并调用其中一个值,但我使用的点表示法给我 mdCounties.type 没有名为 County Transfer 的成员。但我确实创建了一个实例(加勒特和阿勒格尼)???
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
最佳答案
mdCounties
是您的类型。您需要该结构的实例才能访问其实例方法。您的函数参数也没有正确写入。改为这样做:
func mDtransferTaxCalc(purchasePrice: Double, split: Bool, counties: mdCounties) -> Double {
let userCountyTransfer = (purchasePrice) * counties.countyTransfer
return userCountyTransfer
}
关于swift - 如何从函数中的结构访问该值? swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29043239/