swift - 如何从函数中的结构访问该值? swift

标签 swift

我希望能够传入 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/

相关文章:

ios - 使用选定键的 Parse.com 关系查询

swift - 当呈现给具有 webview 的 View Controller 时,警报不显示

swift - 无法在 Ubuntu 14.04 上用 Swift 执行命令

ios - 如何转换Class类型?

ios - swift 错误 : Initializer for conditional binding must have Optional type, 不是 '()'

ios - Xcode 10.2.1 命令 PhaseScriptExecution 失败,退出代码非零

ios - 快速配置深层链接?

ios - 查找 25 个最常出现的字符串

ios - 为 UICollectionViewFlowLayout 提供我自己的初始化程序

ios - 将多个请求合并为一个。可观察数组转化为数组的可观察数组