ios - 无法将“NSAttributedString.Key”类型的值转换为预期的字典键类型“String”错误(swift4.2)
问题描述
从 swift 3 升级到 swift 4.2 时出现以下两行代码错误
let lineattribute : [String: Any] = [
NSForegroundColorAttributeName : UIColor(hexString: "#0f88b7ff")!,
NSUnderlineStyleAttributeName : NSUnderlineStyle.styleSingle.rawValue
]
let attributeString = NSMutableAttributedString(string: "View travelling details", attributes: lineattribute)
解决方案
在Swift 4.2中你必须使用NSAttributedString.Key
而不是String
let lineattribute : [NSAttributedString.Key : Any] = [
.foregroundColor : UIColor(hexString: "#0f88b7ff"),
.underlineStyle : NSUnderlineStyle.styleSingle.rawValue
]
let attributeString = NSMutableAttributedString(string: "View traveling details", attributes: lineattribute)
推荐阅读
- c# - 为什么这个“标签”是一个字段?
- libgit2sharp - 使用 libgit2sharp 将文件签出到之前的提交
- three.js - 为什么three.js 加载器只需要某些浏览器的网络服务器?
- odoo - Odoo 10 安装永远不会完成(设置 odoo)
- react-native - 不能在 react-native 中使用 galmorous 包
- if-statement - Google 表格:如何使用 MATCH 函数创建嵌套的 IF 语句?
- java - 使用 java 分析线程转储
- robotframework - 订阅以获取在机器人框架 MQTT 库中不起作用的消息
- javascript - 为什么车把将脚本模板编译为 CDATA
- c++ - 对于在 AIX OS 上运行的 C++ 应用程序,是否有任何好的动态内存分析器