NSMutableAttributedString:'init(string:attributes:)' 的使用不明确

NSMutableAttributedString: Ambiguous use of 'init(string:attributes:)'

我正在尝试 运行 我几个月前写的代码。现在我使用 Swift 4.2/Xcode 10.1。我在

上收到错误 'init(string:attributes:)' 的模糊使用
let mutableAttributedString = NSMutableAttributedString(string: "", attributes: [:])

我也用 SwiftyAttributes 4.3.0. Here 我发现 public convenience init(string str: String, attributes: [Attribute]),但是我不明白为什么Swift要调用这个函数。

我该如何解决这个问题?是否需要更新 SwiftyAttributes?

问题出在 SwiftyAttributes 4.3.0 中声明的 init 方法中:

extension NSAttributedString {
    public convenience init(string str: String, attributes: [Attribute]) {
        self.init(string: str, attributes: dictionary(from: attributes))
    }
}

在 SwiftyAttributes 5.0.0 中,此方法已重命名为 public convenience init(string str: String, swiftyAttributes attrs: [Attribute])。因此,我更新了 SwiftyAttributes 来解决这个问题。有关添加到 SwiftyAttributes 5.0.0 的修复程序的更多详细信息,请参阅 this link