title: How to set font size on NSAttributedString
body: <p>Edit - This has been marked as duplicate, but as I state below, I am looking for a Swift solution.  Everything I've found is written in Objective C.</p>
  
  <p>I am trying to convert HTML into an NSAttributedString, but can't figure how to set the font style and size.  All of the examples are in Objective C which I'm not skilled in.  How can I set the font style/size to System 15 (as an example)</p>
  
  <pre><code>private func stringFromHtml(string: String) -&gt; NSAttributedString? {
          do {
              let data = string.data(using: String.Encoding.utf8, allowLossyConversion: true)
              if let d = data {
                  let str = try NSAttributedString(data: d,
                                                   options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],                                                  documentAttributes: nil)
                  return str
              }
          } catch {
          }
          return nil
      }
  </code></pre>
  
  <p>EDIT...... I've tried several ways. I can't get it to work.  I'm now getting an error message: Type of expression is ambiguous without more context. It's pointing to the NSAttributedString
  I've tried the following:</p>
  
  <pre><code>let myAttribute = [ NSForegroundColorAttributeName: UIColor.blue ]
  let data = string.data(using: String.Encoding.utf8, allowLossyConversion: true)
    if let d = data {
       let str = try NSAttributedString(data: d,
                         attributes: myAttribute,
                         options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
  </code></pre>