title: How to set heading, subheading, body, footnote, and captions font for dynamic type text styles in Swift?
body: <p>I was working through the <a href="http://www.appcoda.com/intro-text-kit-ios-programming-guide/" rel="noreferrer">Using Text Kit to Manage Text in Your iOS Apps</a> tutorial. It was written for Objective C but I thought I would try to do it anyway using Swift.</p>
  
  <p>However, when I got to the following code I couldn't figure out how to set the heading and other styles for the <code>UITextView</code> using Swift. Here is the Objective C code:</p>
  
  <pre><code>- (IBAction)applyHeadlineStyle:(id)sender {
      [_textView setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]];
  }
  
  - (IBAction)applySubHeadlineStyle:(id)sender {
      [_textView setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]];
  }
  
  - (IBAction)applyBodyStyle:(id)sender {
      [_textView setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]];
  }
  
  - (IBAction)applyFootnoteStyle:(id)sender {
      [_textView setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]];
  }
  
  - (IBAction)applyCaption1Style:(id)sender {
      [_textView setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]];
  }
  
  - (IBAction)applyCaption2Style:(id)sender {
      [_textView setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]];
  }
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>textView.setFont =
  textView.preferredFontForTextStyle =
  </code></pre>
  
  <p>Neither of these seemed to work, though, and I couldn't find any Swift answers on SO.</p>