I am trying to create AttributedString and add the attributes from
typingAttributes(from textView)
The problem is that
.typingAttributes
return
[String, Any]
and
NSAttributedString(string:.. , attributes:[])
needs
[NSAttributedStringKey: Any]
My code:
NSAttributedString(string: "test123", attributes: self.textView.typingAttributes)
I don't want to create for in cycle to go through all keys and change them to
NSAttributedStringKey
Even better solution I think. I created extension.
https://gist.github.com/AltiAntonov/f0f86e7cd04c61118e13f753191b5d9e
Here is my helper class, which I use custom fonts
You can map the
[String: Any]
dictionary to a[NSAttributedStringKey: Any]
dictionary withHere is a possible extension method for that purpose, it is restricted to dictionaries with string keys: