将我的代码从swift3 转换为 4 并得到错误 Cannot convert value of type '[String : Any]' to expected argument type '[NSAttributedStringKey : Any]'
在线的
attributedString.addAttributes(boldAttributes, range: NSRange(location: index, length: linkType.keyPhrase.count))
突出显示粗体属性
这是完整的代码
private func addLink(_ linkType: AttributedURLType, attributedString: NSMutableAttributedString) {
let indeces = attributedString.string.indices(of: linkType.keyPhrase)
let boldAttributes: [String : Any] = [
NSAttributedStringKey.font.rawValue: LocalConstants.termsBoldFont,
NSAttributedStringKey.link.rawValue: linkType.url
]
for index in indeces {
attributedString.addAttributes(boldAttributes, range: NSRange(location: index, length: linkType.keyPhrase.count))
}
}