【问题标题】:Swift 4 migration getting error Cannot convert value of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?'Swift 4 迁移出现错误无法转换类型“[String:AnyObject]?”的值到预期的参数类型“[NSAttributedStringKey:Any]?”
【发布时间】:2017-10-30 12:03:02
【问题描述】:
let linkTextAttributes = [
NSAttributedStringKey.underlineStyle: NSNumber(value: NSUnderlineStyle.styleSingle.rawValue as Int),
NSAttributedStringKey.foregroundColor: FAColor.blackColor()
]
self.lblPinDidNotMatchDescription.linkTextAttributes = linkTextAttributes
在 Swift 4 迁移时出错
“无法转换类型 '[String : AnyObject] 的值?'到预期的参数类型 '[NSAttributedStringKey : Any]?'"。
有什么帮助吗?
【问题讨论】:
标签:
migration
ios11
swift4
【解决方案1】:
改成NSUnderlineStyle.styleSingle.rawValue
例子
let linkTextAttributes: [NSAttributedStringKey: Any] = [
NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.foregroundColor: UIColor.black
]