Converting a NSAttributedString into a NSString using Swift

ixany picture ixany · Aug 25, 2014 · Viewed 38.6k times · Source

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?

Answer

mipadi picture mipadi · Aug 25, 2014

Use the string property on NSMutableAttributedString:

var attributedString = NSMutableAttributedString(string: "hello, world!")
var s = attributedString.string