I have a string of link, but it contains the Chinese.
And then my app will crash.
How to prevent whether url contains Chinese or not, it can show the link normally .
var youTextLabel = UILabel()
var message = "https://zh.wikipedia.org/wiki/斯蒂芬·科里"
let linkAttributes = [NSLinkAttributeName: NSURL(string: message)!, //This get error!!
NSForegroundColorAttributeName: UIColor.blue,
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue] as [String : Any]
let attributedString = NSMutableAttributedString(string: message)
let urlCharacterCount = message.characters.count
attributedString.setAttributes(linkAttributes, range: NSMakeRange(0, urlCharacterCount))
youTextLabel.attributedText = attributedString
error message:
fatal error: unexpectedly found nil while unwrapping an Optional value