I tried all the best to search all possible solution to get this to work. I am wondering if I can change the already attributed text to a new attributed text with other attributes without changing it to string.
func updateSelectedText(attributes: [NSAttributedString.Key : Any]) {
let selectedRange = textView.selectedRange
let mutableAttributesString = NSMutableAttributedString(attributedString: textView.attributedText)
mutableAttributesString.setAttributes(attributes, range: selectedRange)
print(attributes)
print(selectedRange)
print(mutableAttributesString)
}