NSMutableAttributedString:'init(string:attributes :)'的模糊使用

问题描述 投票:0回答:1

我试图运行我几个月前写的代码。现在我使用Swift 4.2 / Xcode 10.1。我得到错误模糊地使用'init(string:attributes :)'

let mutableAttributedString = NSMutableAttributedString(string: "", attributes: [:])

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

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

swift swift4.2 nsmutableattributedstring
1个回答
1
投票

问题出在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

© www.soinside.com 2019 - 2024. All rights reserved.