Converting a NSAttributedString into a NSString using Swift

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?


Solution 1:

Use the string property on NSMutableAttributedString:

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

Solution 2:

If you strictly want an NSString, not a String use the following:

let s = attributedString.string as NSString

Solution 3:

if you want to keep the atributted string simply use yourLabel.attributedText = atributedTtext