I have a NSMutableAttributedString
and want to convert it back into a simple String
.
var attributedString = NSMutableAttributedString(string: "hello w0rld")
How can I get just the String
out of a NSMutableAttributedString
the easiest?
An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string.
let label = UILabel() label. attributedText = NSMutableAttributedString() . bold("Address: ") .
Changing an Attributed String First create an NSMutableAttributedString with a new font attribute. You don't use textView. text . Then append another attributed string that doesn't have any attributes set.
Use the string
property on NSMutableAttributedString
:
var attributedString = NSMutableAttributedString(string: "hello, world!") var s = attributedString.string
If you strictly want an NSString
, not a String
use the following:
let s = attributedString.string as NSString
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With