Search code examples
swiftstringnsattributedstringnsmutableattributedstring

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

  • Use the string property on NSMutableAttributedString:

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