I'm facing a NSInvalidArgumentException
exception after upgrading a project to Swift 4.2 (conversion from 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'
It's something related with a NSMutableAttributedString
and the code is adding some attributes, for example, a NSAttributedString.Key.underlineStyle
.
The exception happens when the attributed string is about to be assigned: textView.attributedText = mutableAttributedString
.
UPDATE:
The code was working in Swift 4:
mutableAttributedString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.styleNone.rawValue, range: range)
But with Swift 4.2, the compiler suggests changing the NSUnderlineStyle.styleNone.rawValue
to NSUnderlineStyle.none.rawValue
After accepting the change, the compiler started complaining about "'none' is unavailable: use [] to construct an empty option set":
mutableAttributedString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.none.rawValue, range: range)
^~~~~ 'none' is unavailable: use [] to construct an empty option set
.rawValue
to your underlineStyle – Parasitize