【发布时间】:2019-02-23 19:11:24
【问题描述】:
在将项目升级到 Swift 4.2(从 4.0 转换)后,我遇到了 NSInvalidArgumentException 异常。
2018-09-19 15:37:33.253482+0100 <redacted>-beta[3715:1010421] -[Swift._EmptyArrayStorage _getValue:forType:]: unrecognized selector sent to instance 0x107e6c290
2018-09-19 15:37:33.254312+0100 <redacted>-beta[3715:1010421] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Swift._EmptyArrayStorage _getValue:forType:]: unrecognized selector sent to instance 0x107e6c290'
它与 NSMutableAttributedString 和它添加一些属性的代码有关,例如 NSAttributedString.Key.underlineStyle。
在即将分配属性字符串时发生异常:textView.attributedText = mutableAttributedString。
更新:
所以,它在 Swift 4 中运行:
mutableAttributedString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.styleNone.rawValue, range: range)
然后,在 Swift 4.2 中,编译器建议将 NSUnderlineStyle.styleNone.rawValue 更改为 NSUnderlineStyle.none.rawValue
之后,编译器开始大喊“'none' 不可用:使用 [] 构造一个空的选项集”:
mutableAttributedString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.none.rawValue, range: range)
^~~~~ 'none' is unavailable: use [] to construct an empty option set
【问题讨论】:
-
尝试将
.rawValue添加到您的下划线样式
标签: swift nsmutableattributedstring swift4.2