NSInvalidArgumentException
将项目升级到 Swift 4.2(从 4.0 转换)后,我遇到了异常。
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'
它与 a 相关,NSMutableAttributedString
并且它正在添加一些属性的代码,例如 a 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