TIL how to get string from AttributedString in Swift
I was confused today I cannot access regular string of AttributedString
in Swift. In case of NSAttributedString
, it was trivial as NSAttributedString
is subclass of NSString
. I haven’t found straight way in documentation so I googled. Thread in swift forums AttributedString to String mentions only what I’ve got from documentation - go over characters view:
let string = String(attributedString.characters)
I could add one more way - use NSAttributedString
as middleware:
let string = NSAttributedString(attributedString).string