【问题标题】:Runtime error after installing a pod that uses NumberFormatter安装使用 NumberFormatter 的 pod 后出现运行时错误
【发布时间】:2019-01-16 09:49:31
【问题描述】:

我正在使用 DoubleNSNumber 的扩展来生成代表价格的字符串。

extension NSNumber {

    internal func getPriceString(currencyCode: String? = nil, numberOfFractionDigits: Int = 2) -> String? {
        let numberFormatter = NumberFormatter()
        numberFormatter.numberStyle = .currency
        numberFormatter.locale = Locale.current
        numberFormatter.currencyCode = currencyCode ?? Locale.current.currencyCode ?? "USD"
        numberFormatter.minimumFractionDigits = numberOfFractionDigits
        numberFormatter.maximumFractionDigits = numberOfFractionDigits
        return numberFormatter.string(from: self)
    }

}

extension Double {

    public func getPriceString(currencyCode: String? = nil, numberOfFractionDigits: Int = 2) -> String? {
        return NSNumber(value: self).getPriceString(currencyCode: currencyCode, numberOfFractionDigits: numberOfFractionDigits)
    }

}

此代码在添加到主项目时运行良好。我可以对服务器返回的数字调用Double 方法来获取有效的价格字符串。例如:

priceLabel.text = item.price.getPriceString(currencyCode: "EUR", numberOfFractionDigits: 0)
// €1,024

但是,我的目标是将这些扩展程序移到可以在多个项目中使用的 pod 中。当从主项目调用添加到 pod 的相同代码时,我得到运行时错误。

为什么会发生这种情况,我该如何解决?

【问题讨论】:

    标签: swift cocoapods ios-frameworks


    【解决方案1】:

    安装/更新 pod 后必须清理项目文件夹。

    Shift ⇧ + Command ⌘ + K

    选项⌥ + Shift ⇧ + 命令⌘ + K

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 2016-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-30
      • 1970-01-01
      相关资源
      最近更新 更多