title: Error using Codable for NSAttributedString
body: <p>I'm trying to implement Codable for a class which contains a NSAttributedString, but I get errors at compile time:</p>
  
  <pre><code>try container.encode(str, forKey: .str)
  </code></pre>
  
  <blockquote>
    <p>error ambiguous reference to member 'encode(_:forKey:)'</p>
  </blockquote>
  
  <p>and </p>
  
  <pre><code>str = try container.decode(NSMutableAttributedString.self, forKey: .str)
  </code></pre>
  
  <blockquote>
    <p>error: No 'decode' candidates produce the expected contextual type 'NSAttributedString'</p>
  </blockquote>
  
  <p>I can get around it by using the NSData from the string, but thought this should work I would have thought</p>
  
  <pre><code>class Text : Codable {
      var str : NSAttributedString
  
      enum CodingKeys: String, CodingKey {
          case str
      }
  
      func encode(to encoder: Encoder) throws {
          var container = encoder.container(keyedBy: CodingKeys.self)
          try container.encode(str, forKey: .str). &lt;-- error ambiguous reference to member 'encode(_:forKey:)'
      }
  
      required init(from decoder: Decoder) throws {
          let container = try decoder.container(keyedBy: CodingKeys.self)
          str = try container.decode(NSMutableAttributedString.self, forKey: .str)  &lt;-- error: No 'decode' candidates produce the expected contextual type 'NSAttributedString'
      }
  }
  </code></pre>